2019-02-23 16:58:58 +00:00
#!/bin/sh
2017-07-07 13:02:43 +00:00
set -e
2017-07-18 11:55:37 +00:00
chmod +x /parseurl.py
2017-07-18 15:33:05 +00:00
/parseurl.py ETHERPAD_DB_
2019-02-23 16:58:58 +00:00
eval " $( /parseurl.py ETHERPAD_DB_) "
2017-07-07 13:02:43 +00:00
# ETHERPAD_DB_PASSWORD is mandatory in mysql container, so we're not offering
# 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
2017-07-18 11:55:37 +00:00
# if [ "$ETHERPAD_DB_USERNAME" = 'root' ]; then
# : ${ETHERPAD_DB_PASSWORD:=$MYSQL_ENV_MYSQL_ROOT_PASSWORD}
# fi
if [ -z " $ETHERPAD_DB_USERNAME " ] ; then
echo >& 2 'error: missing required ETHERPAD_DB_USERNAME environment variable'
echo >& 2 ' Did you forget to -e ETHERPAD_DB_USERNAME=... ?'
exit 1
2017-07-07 13:02:43 +00:00
fi
if [ -z " $ETHERPAD_DB_PASSWORD " ] ; then
echo >& 2 'error: missing required ETHERPAD_DB_PASSWORD environment variable'
echo >& 2 ' Did you forget to -e ETHERPAD_DB_PASSWORD=... ?'
exit 1
fi
2019-02-23 16:58:58 +00:00
RANDOM_STRING = " $( node -p "require('crypto').randomBytes(32).toString('hex')" ) } "
# 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_SESSION_KEY = " ${ ETHERPAD_SESSION_KEY :- $RANDOM_STRING } "
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 \
" -u ${ ETHERPAD_DB_USERNAME } " \
" -p ${ ETHERPAD_DB_PASSWORD } " \
" -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
2017-07-07 13:02:43 +00:00
# mysql database does not exist, create it
echo " Creating database ${ ETHERPAD_DB_NAME } "
2019-02-23 16:58:58 +00:00
mysql " -u ${ ETHERPAD_DB_USERNAME } " \
" -p ${ ETHERPAD_DB_PASSWORD } " \
" -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
echo "Creating database configuration"
2017-07-07 13:02:43 +00:00
cat <<- EOF > settings.json
{
"title" : " ${ ETHERPAD_TITLE } " ,
"ip" : "0.0.0.0" ,
"port" :${ ETHERPAD_PORT } ,
2020-03-20 18:57:50 +00:00
"skinName" : "colibris" ,
2017-07-07 13:02:43 +00:00
"sessionKey" : " ${ ETHERPAD_SESSION_KEY } " ,
2021-04-30 12:21:42 +00:00
"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."
2017-07-07 13:02:43 +00:00
"dbType" : "mysql" ,
"dbSettings" : {
2017-07-18 11:55:37 +00:00
"user" : " ${ ETHERPAD_DB_USERNAME } " ,
2017-07-07 13:02:43 +00:00
"host" : " ${ ETHERPAD_DB_HOST } " ,
"password" : " ${ ETHERPAD_DB_PASSWORD } " ,
2021-04-30 12:21:42 +00:00
"database" : " ${ ETHERPAD_DB_NAME } " ,
"charset" : "utf8mb4"
2017-07-07 13:02:43 +00:00
} ,
EOF
2019-02-23 16:58:58 +00:00
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 "
2017-07-07 13:02:43 +00:00
cat <<- EOF >> settings.json
"users" : {
" ${ ETHERPAD_ADMIN_USER } " : {
"password" : " ${ ETHERPAD_ADMIN_PASSWORD } " ,
"is_admin" : true
}
} ,
EOF
fi
cat <<- EOF >> settings.json
}
EOF
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