refactor: Use shell version of URL parser
This commit is contained in:
parent
b9ebe9704e
commit
5a658e416b
4 changed files with 95 additions and 125 deletions
|
@ -7,7 +7,7 @@ ENV ETHERPAD_VERSION 1.8.13
|
||||||
|
|
||||||
# RUN = docker run ... + docker commit
|
# RUN = docker run ... + docker commit
|
||||||
RUN apt-get update \
|
RUN apt-get update \
|
||||||
&& apt-get install -y curl unzip mariadb-client python netcat \
|
&& apt-get install -y curl unzip mariadb-client netcat \
|
||||||
&& apt-get clean \
|
&& apt-get clean \
|
||||||
&& rm -r /var/lib/apt/lists/*
|
&& rm -r /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
|
120
entrypoint.sh
Normal file → Executable file
120
entrypoint.sh
Normal file → Executable file
|
@ -1,27 +1,25 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
chmod +x /parseurl.py
|
eval "$(sh /parseurl.sh "$DATABASE_URL" ETHERPAD_DB)"
|
||||||
/parseurl.py ETHERPAD_DB_
|
|
||||||
eval "$(/parseurl.py ETHERPAD_DB_)"
|
|
||||||
|
|
||||||
# ETHERPAD_DB_PASSWORD is mandatory in mysql container, so we're not offering
|
# ETHERPAD_DB_PASS 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
|
# 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
|
# using the password from the env variable MYSQL_ENV_MYSQL_ROOT_PASSWORD
|
||||||
# if [ "$ETHERPAD_DB_USERNAME" = 'root' ]; then
|
# if [ "$ETHERPAD_DB_USER" = 'root' ]; then
|
||||||
# : ${ETHERPAD_DB_PASSWORD:=$MYSQL_ENV_MYSQL_ROOT_PASSWORD}
|
# : ${ETHERPAD_DB_PASS:=$MYSQL_ENV_MYSQL_ROOT_PASSWORD}
|
||||||
# fi
|
# fi
|
||||||
|
|
||||||
if [ -z "$ETHERPAD_DB_USERNAME" ]; then
|
if [ -z "$ETHERPAD_DB_USER" ]; then
|
||||||
echo >&2 'error: missing required ETHERPAD_DB_USERNAME environment variable'
|
echo >&2 'error: missing required ETHERPAD_DB_USER environment variable'
|
||||||
echo >&2 ' Did you forget to -e ETHERPAD_DB_USERNAME=... ?'
|
echo >&2 ' Did you forget to -e ETHERPAD_DB_USER=... ?'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$ETHERPAD_DB_PASSWORD" ]; then
|
if [ -z "$ETHERPAD_DB_PASS" ]; then
|
||||||
echo >&2 'error: missing required ETHERPAD_DB_PASSWORD environment variable'
|
echo >&2 'error: missing required ETHERPAD_DB_PASS environment variable'
|
||||||
echo >&2 ' Did you forget to -e ETHERPAD_DB_PASSWORD=... ?'
|
echo >&2 ' Did you forget to -e ETHERPAD_DB_PASS=... ?'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
RANDOM_STRING="$(node -p "require('crypto').randomBytes(32).toString('hex')")}"
|
RANDOM_STRING="$(node -p "require('crypto').randomBytes(32).toString('hex')")}"
|
||||||
|
@ -47,62 +45,62 @@ sleep 1
|
||||||
|
|
||||||
# Check if database already exists
|
# Check if database already exists
|
||||||
RESULT="$(mysql \
|
RESULT="$(mysql \
|
||||||
"-u${ETHERPAD_DB_USERNAME}" \
|
"-u${ETHERPAD_DB_USER}" \
|
||||||
"-p${ETHERPAD_DB_PASSWORD}" \
|
"-p${ETHERPAD_DB_PASS}" \
|
||||||
"-P${ETHERPAD_DB_PORT}" \
|
"-P${ETHERPAD_DB_PORT}" \
|
||||||
"-h${ETHERPAD_DB_HOST}" \
|
"-h${ETHERPAD_DB_HOST}" \
|
||||||
--skip-column-names \
|
--skip-column-names \
|
||||||
-e "SHOW DATABASES LIKE '${ETHERPAD_DB_NAME}'")"
|
-e "SHOW DATABASES LIKE '${ETHERPAD_DB_NAME}'")"
|
||||||
|
|
||||||
if [ "$RESULT" != "$ETHERPAD_DB_NAME" ]; then
|
if [ "$RESULT" != "$ETHERPAD_DB_NAME" ]; then
|
||||||
# mysql database does not exist, create it
|
# mysql database does not exist, create it
|
||||||
echo "Creating database ${ETHERPAD_DB_NAME}"
|
echo "Creating database ${ETHERPAD_DB_NAME}"
|
||||||
|
|
||||||
mysql "-u${ETHERPAD_DB_USERNAME}" \
|
mysql "-u${ETHERPAD_DB_USER}" \
|
||||||
"-p${ETHERPAD_DB_PASSWORD}" \
|
"-p${ETHERPAD_DB_PASS}" \
|
||||||
"-P${ETHERPAD_DB_PORT}" \
|
"-P${ETHERPAD_DB_PORT}" \
|
||||||
"-h${ETHERPAD_DB_HOST}" \
|
"-h${ETHERPAD_DB_HOST}" \
|
||||||
-e "create database ${ETHERPAD_DB_NAME}"
|
-e "create database ${ETHERPAD_DB_NAME}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! [ -f settings.json ]; then
|
if ! [ -f settings.json ]; then
|
||||||
echo "Creating database configuration"
|
echo "Creating database configuration"
|
||||||
cat <<- EOF > settings.json
|
cat <<- EOF > settings.json
|
||||||
{
|
{
|
||||||
"title": "${ETHERPAD_TITLE}",
|
"title": "${ETHERPAD_TITLE}",
|
||||||
"ip": "0.0.0.0",
|
"ip": "0.0.0.0",
|
||||||
"port" :${ETHERPAD_PORT},
|
"port" :${ETHERPAD_PORT},
|
||||||
"skinName": "colibris",
|
"skinName": "colibris",
|
||||||
"sessionKey" : "${ETHERPAD_SESSION_KEY}",
|
"sessionKey" : "${ETHERPAD_SESSION_KEY}",
|
||||||
"trustProxy" : false,
|
"trustProxy" : false,
|
||||||
"minify" : true,
|
"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.",
|
"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",
|
"dbType" : "mysql",
|
||||||
"dbSettings" : {
|
"dbSettings" : {
|
||||||
"user" : "${ETHERPAD_DB_USERNAME}",
|
"user" : "${ETHERPAD_DB_USER}",
|
||||||
"host" : "${ETHERPAD_DB_HOST}",
|
"host" : "${ETHERPAD_DB_HOST}",
|
||||||
"password": "${ETHERPAD_DB_PASSWORD}",
|
"password": "${ETHERPAD_DB_PASS}",
|
||||||
"database": "${ETHERPAD_DB_NAME}"
|
"database": "${ETHERPAD_DB_NAME}"
|
||||||
},
|
},
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
if [ -n "$ETHERPAD_ADMIN_PASSWORD" ]; then
|
if [ -n "$ETHERPAD_ADMIN_PASSWORD" ]; then
|
||||||
ETHERPAD_ADMIN_USER="${ETHERPAD_ADMIN_USER:-admin}"
|
ETHERPAD_ADMIN_USER="${ETHERPAD_ADMIN_USER:-admin}"
|
||||||
echo "Creating admin user configuration for $ETHERPAD_ADMIN_USER/$ETHERPAD_ADMIN_PASSWORD"
|
echo "Creating admin user configuration for $ETHERPAD_ADMIN_USER/$ETHERPAD_ADMIN_PASSWORD"
|
||||||
|
|
||||||
cat <<- EOF >> settings.json
|
cat <<-EOF >> settings.json
|
||||||
"users": {
|
"users": {
|
||||||
"${ETHERPAD_ADMIN_USER}": {
|
"${ETHERPAD_ADMIN_USER}": {
|
||||||
"password": "${ETHERPAD_ADMIN_PASSWORD}",
|
"password": "${ETHERPAD_ADMIN_PASSWORD}",
|
||||||
"is_admin": true
|
"is_admin": true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat <<- EOF >> settings.json
|
cat <<- EOF >> settings.json
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! grep -q '/* GLENUX BEGIN */' src/static/css/pad.css ; then
|
if ! grep -q '/* GLENUX BEGIN */' src/static/css/pad.css ; then
|
||||||
|
|
63
parseurl.py
63
parseurl.py
|
@ -1,63 +0,0 @@
|
||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import os
|
|
||||||
from urlparse import urlparse
|
|
||||||
|
|
||||||
prefix = sys.argv[1]
|
|
||||||
# print os.environ.keys
|
|
||||||
uri_str = os.environ['DATABASE_URL']
|
|
||||||
uri = urlparse(uri_str)
|
|
||||||
|
|
||||||
db_netloc = uri.netloc
|
|
||||||
|
|
||||||
db_credential = None
|
|
||||||
db_username = None
|
|
||||||
db_password = None
|
|
||||||
db_host = None
|
|
||||||
db_port = None
|
|
||||||
|
|
||||||
if db_netloc.find("@") >= 0 :
|
|
||||||
tmp_arr1 = db_netloc.split('@')
|
|
||||||
db_credential = tmp_arr1[0]
|
|
||||||
db_host = tmp_arr1[1]
|
|
||||||
|
|
||||||
if db_credential and db_credential.find(':') >= 0 :
|
|
||||||
tmp_arr2 = db_credential.split(':')
|
|
||||||
db_username = tmp_arr2[0]
|
|
||||||
db_password = tmp_arr2[1]
|
|
||||||
|
|
||||||
if db_host and db_host.find(':') >= 0 :
|
|
||||||
tmp_arr3 = db_host.split(':')
|
|
||||||
db_host = tmp_arr3[0]
|
|
||||||
db_port = tmp_arr3[1]
|
|
||||||
|
|
||||||
db_path = uri.path
|
|
||||||
db_scheme = uri.scheme
|
|
||||||
db_query = uri.query
|
|
||||||
db_fragment = uri.fragment
|
|
||||||
|
|
||||||
if db_scheme :
|
|
||||||
print(prefix + 'SCHEME=' + db_scheme)
|
|
||||||
|
|
||||||
if db_username :
|
|
||||||
print(prefix + 'USERNAME=' + db_username)
|
|
||||||
|
|
||||||
if db_password :
|
|
||||||
print(prefix + 'PASSWORD=' + db_password)
|
|
||||||
|
|
||||||
if db_host :
|
|
||||||
print(prefix + 'HOST=' + db_host)
|
|
||||||
|
|
||||||
if db_port :
|
|
||||||
print(prefix + 'PORT=' + db_port)
|
|
||||||
|
|
||||||
if db_path :
|
|
||||||
print(prefix + 'NAME=' + db_path[1:])
|
|
||||||
|
|
||||||
if db_query :
|
|
||||||
print(prefix + 'QUERY=' + db_query)
|
|
||||||
|
|
||||||
if db_fragment :
|
|
||||||
print(prefix + 'FRAGMENT=' + db_fragment)
|
|
||||||
|
|
35
parseurl.sh
Executable file
35
parseurl.sh
Executable file
|
@ -0,0 +1,35 @@
|
||||||
|
#!/bin/sh
|
||||||
|
# Referenced and tweaked from http://stackoverflow.com/questions/6174220/parse-url-in-shell-script#6174447
|
||||||
|
|
||||||
|
url="$1"
|
||||||
|
prefix="$2"
|
||||||
|
proto="$(echo "$url" | grep :// | sed -e 's,^\(.*\)://.*,\1,g')"
|
||||||
|
# remove the protocol
|
||||||
|
workurl="$(echo "$url" |sed -e "s,^$proto://,,")"
|
||||||
|
# extract the user (if any)
|
||||||
|
userpass="$(echo "$workurl" | grep @ | cut -d@ -f1)"
|
||||||
|
pass="$(echo "$userpass"| grep : | cut -d: -f2)"
|
||||||
|
if [ -n "$pass" ]; then
|
||||||
|
user="$(echo "$userpass" | grep : | cut -d: -f1)"
|
||||||
|
else
|
||||||
|
user="$userpass"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# extract the host
|
||||||
|
hostport="$(echo "$workurl" |sed -e "s,$userpass@,," | cut -d/ -f1)"
|
||||||
|
# by request - try to extract the port
|
||||||
|
port="$(echo "$hostport" | sed -e 's,^.*:,:,g' -e 's,.*:\([0-9]*\).*,\1,g' -e 's,[^0-9],,g')"
|
||||||
|
host="$(echo "$hostport" | cut -d: -f1)"
|
||||||
|
# extract the path (if any)
|
||||||
|
path="/$(echo "$workurl" | grep / | cut -d/ -f2-)"
|
||||||
|
name="$(echo "$workurl" | grep / | cut -d/ -f2-)"
|
||||||
|
|
||||||
|
echo "${prefix}_URL=\"$url\""
|
||||||
|
echo "${prefix}_PROTO=\"$proto\""
|
||||||
|
echo "${prefix}_USER=\"$user\""
|
||||||
|
echo "${prefix}_PASS=\"$pass\""
|
||||||
|
echo "${prefix}_HOST=\"$host\""
|
||||||
|
echo "${prefix}_PORT=\"$port\""
|
||||||
|
echo "${prefix}_PATH=\"$path\""
|
||||||
|
echo "${prefix}_NAME=\"$name\""
|
||||||
|
|
Loading…
Reference in a new issue