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/*
|
||||||
|
|
||||||
|
|
34
entrypoint.sh
Normal file → Executable file
34
entrypoint.sh
Normal file → Executable file
|
@ -1,26 +1,24 @@
|
||||||
#!/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
|
||||||
|
|
||||||
|
@ -47,8 +45,8 @@ 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 \
|
||||||
|
@ -58,8 +56,8 @@ 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}"
|
||||||
|
@ -79,9 +77,9 @@ if ! [ -f settings.json ]; then
|
||||||
"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
|
||||||
|
|
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