Compare commits
1 commit
master
...
master-nod
Author | SHA1 | Date | |
---|---|---|---|
b0f4ecc13a |
7 changed files with 195 additions and 206 deletions
74
Dockerfile
74
Dockerfile
|
@ -1,63 +1,45 @@
|
||||||
# Stable version of etherpad doesn't support npm 2
|
# Stable version of etherpad doesn't support npm 2
|
||||||
|
|
||||||
FROM node:18.1
|
FROM node:14-slim
|
||||||
MAINTAINER Glenn Y. Rolland <glenux@glenux.net>
|
MAINTAINER Glenn Y. Rolland <glenux@glenux.net>
|
||||||
|
|
||||||
ENV ETHERPAD_VERSION 1.8.18
|
ENV ETHERPAD_VERSION 1.8.7
|
||||||
|
|
||||||
RUN apt-get update \
|
# RUN = docker run ... + docker commit
|
||||||
&& apt-get install -y unzip mariadb-client netcat \
|
RUN apt-get update && \
|
||||||
&& apt-get clean \
|
apt-get install -y curl unzip mysql-client python netcat && \
|
||||||
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
|
rm -r /var/lib/apt/lists/*
|
||||||
&& truncate -s 0 /var/log/*log
|
|
||||||
|
|
||||||
RUN cd /opt \
|
WORKDIR /opt/
|
||||||
&& wget \
|
|
||||||
|
RUN curl -SL \
|
||||||
https://github.com/ether/etherpad-lite/archive/${ETHERPAD_VERSION}.zip \
|
https://github.com/ether/etherpad-lite/archive/${ETHERPAD_VERSION}.zip \
|
||||||
-O etherpad.zip \
|
> etherpad.zip && unzip etherpad && \
|
||||||
&& unzip etherpad \
|
rm etherpad.zip && \
|
||||||
&& rm etherpad.zip \
|
mv etherpad-lite-${ETHERPAD_VERSION} etherpad-lite
|
||||||
&& mv etherpad-lite-${ETHERPAD_VERSION} etherpad \
|
|
||||||
&& useradd --home-dir /opt/etherpad etherpad \
|
|
||||||
&& chown -R etherpad:etherpad /opt/etherpad
|
|
||||||
|
|
||||||
COPY --chown=etherpad parseurl.sh /parseurl.sh
|
WORKDIR /opt/etherpad-lite
|
||||||
COPY --chown=etherpad entrypoint.sh /entrypoint.sh
|
|
||||||
|
|
||||||
|
COPY parseurl.py /parseurl.py
|
||||||
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
|
|
||||||
WORKDIR /opt/etherpad
|
# Pre-install
|
||||||
USER etherpad
|
RUN bin/installDeps.sh && rm settings.json \
|
||||||
|
&& chmod +x /entrypoint.sh \
|
||||||
# Pre-install some plugins
|
&& sed -i 's/^node/exec\ node/' bin/run.sh \
|
||||||
RUN bin/installDeps.sh \
|
&& ln -s var/settings.json settings.json \
|
||||||
&& cd src \
|
&& npm install \
|
||||||
&& npm install --save-prod \
|
ep_author_neat ep_headings2 \
|
||||||
github:alxndr42/ep_expiration \
|
ep_set_title_on_pad ep_adminpads \
|
||||||
ep_author_neat \
|
ep_workspaces ep_comments_page \
|
||||||
ep_headings2 \
|
ep_font_color ep_table_of_contents \
|
||||||
ep_comments_page \
|
&& npm audit fix
|
||||||
ep_font_color \
|
|
||||||
ep_offline_edit \
|
|
||||||
ep_prompt_for_name \
|
|
||||||
ep_workspaces \
|
|
||||||
ep_table_of_contents \
|
|
||||||
ep_adminpads \
|
|
||||||
&& cd .. \
|
|
||||||
&& rm settings.json \
|
|
||||||
&& ln -s var/settings.json settings.json
|
|
||||||
|
|
||||||
# ep_delete_after_delay \
|
|
||||||
# ep_set_title_on_pad \
|
|
||||||
|
|
||||||
# && sed -i 's/^node/exec\ node/' bin/run.sh \
|
|
||||||
|
|
||||||
# ep_mypads
|
# ep_mypads
|
||||||
|
|
||||||
# meta-données
|
# meta-données
|
||||||
VOLUME /opt/etherpad/var
|
VOLUME /opt/etherpad-lite/var
|
||||||
EXPOSE 9001
|
EXPOSE 9001
|
||||||
|
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
CMD ["./src/bin/run.sh"]
|
CMD ["bin/run.sh", "--root"]
|
||||||
# bin/run.sh
|
|
||||||
|
|
||||||
|
|
13
Makefile
13
Makefile
|
@ -6,19 +6,10 @@ TAG:=$(shell TZ=UTC date +"%Y%m%d")
|
||||||
all:
|
all:
|
||||||
|
|
||||||
build:
|
build:
|
||||||
docker-compose build
|
docker build -t $(USERNAME)/$(IMAGE):$(TAG) .
|
||||||
|
|
||||||
run:
|
run:
|
||||||
docker-compose up --detach
|
# remplir ici
|
||||||
|
|
||||||
logs:
|
|
||||||
docker-compose logs -f
|
|
||||||
|
|
||||||
shell:
|
|
||||||
docker-compose exec etherpad bash
|
|
||||||
|
|
||||||
kill:
|
|
||||||
docker-compose kill
|
|
||||||
|
|
||||||
test: build
|
test: build
|
||||||
# remplir ici
|
# remplir ici
|
||||||
|
|
64
README.md
64
README.md
|
@ -1,7 +1,15 @@
|
||||||
# Etherpad Lite image for docker
|
# Etherpad Lite image for docker
|
||||||
|
|
||||||
|
|
||||||
|
This is a docker image for [Etherpad Lite](http://etherpad.org/) collaborative
|
||||||
|
text editor. The Dockerfile for this image has been inspired by the
|
||||||
|
[official Wordpress](https://registry.hub.docker.com/_/wordpress/) Dockerfile and
|
||||||
|
[johbo's etherpad-lite](https://registry.hub.docker.com/u/johbo/etherpad-lite/)
|
||||||
|
image.
|
||||||
|
|
||||||
This image uses an mysql container for the backend for the pads. It is based
|
This image uses an mysql container for the backend for the pads. It is based
|
||||||
on latest nodejs image.
|
on debian jessie instead of the official node docker image, since the latest
|
||||||
|
stable version of etherpad-lite does not support npm 2.
|
||||||
|
|
||||||
## About Etherpad Lite
|
## About Etherpad Lite
|
||||||
|
|
||||||
|
@ -9,7 +17,7 @@ on latest nodejs image.
|
||||||
|
|
||||||
Etherpad allows you to edit documents collaboratively in real-time, much like a live multi-player editor that runs in your browser. Write articles, press releases, to-do lists, etc. together with your friends, fellow students or colleagues, all working on the same document at the same time.
|
Etherpad allows you to edit documents collaboratively in real-time, much like a live multi-player editor that runs in your browser. Write articles, press releases, to-do lists, etc. together with your friends, fellow students or colleagues, all working on the same document at the same time.
|
||||||
|
|
||||||
![alt text](http://i.imgur.com/zYrGkg3.gif "Etherpad in action")
|
![alt text](http://i.imgur.com/zYrGkg3.gif "Etherpad in action on PrimaryPad")
|
||||||
|
|
||||||
All instances provide access to all data through a well-documented API and supports import/export to many major data exchange formats. And if the built-in feature set isn't enough for you, there's tons of plugins that allow you to customize your instance to suit your needs.
|
All instances provide access to all data through a well-documented API and supports import/export to many major data exchange formats. And if the built-in feature set isn't enough for you, there's tons of plugins that allow you to customize your instance to suit your needs.
|
||||||
|
|
||||||
|
@ -17,44 +25,26 @@ You don't need to set up a server and install Etherpad in order to use it. Just
|
||||||
|
|
||||||
## Quickstart
|
## Quickstart
|
||||||
|
|
||||||
Copy-paste the following content in a `docker-compose.yml` file
|
First you need a running mysql container, for example:
|
||||||
|
|
||||||
```yaml
|
```bash
|
||||||
---
|
$ docker network create ep_network
|
||||||
version: "3.4"
|
$ docker run -d --network ep_network -e MYSQL_ROOT_PASSWORD=password --name ep_mysql mysql
|
||||||
|
|
||||||
services:
|
|
||||||
db:
|
|
||||||
image: mariadb:10.3
|
|
||||||
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
|
||||||
volumes:
|
|
||||||
- db_data:/var/lib/mysql
|
|
||||||
environment:
|
|
||||||
MARIADB_ROOT_PASSWORD: insecure
|
|
||||||
MARIADB_DATABASE: etherpad
|
|
||||||
|
|
||||||
etherpad:
|
|
||||||
build:
|
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
image: glenux/etherpad:latest
|
|
||||||
environment:
|
|
||||||
DATABASE_URL: mysql://root:insecure:3306@db/etherpad
|
|
||||||
ETHERPAD_ADMIN_USER: admin
|
|
||||||
ETHERPAD_ADMIN_PASSWORD: insecure
|
|
||||||
NODE_ENV: production
|
|
||||||
ports:
|
|
||||||
- 9001:9001
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
db_data:
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Then run `docker-compose up`
|
Finally you can start an instance of Etherpad Lite:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ docker run -d \
|
||||||
|
--network ep_network \
|
||||||
|
-e ETHERPAD_DB_HOST=ep_mysql \
|
||||||
|
-e ETHERPAD_DB_PASSWORD=password \
|
||||||
|
-p 9001:9001 \
|
||||||
|
tvelocity/etherpad-lite
|
||||||
|
```
|
||||||
|
|
||||||
Etherpad will automatically create an `etherpad` database in the specified mysql
|
Etherpad will automatically create an `etherpad` database in the specified mysql
|
||||||
server if it does not already exist.
|
server if it does not already exist.
|
||||||
|
|
||||||
You can now access Etherpad Lite from http://localhost:9001/
|
You can now access Etherpad Lite from http://localhost:9001/
|
||||||
|
|
||||||
## Environment variables
|
## Environment variables
|
||||||
|
@ -63,6 +53,9 @@ This image supports the following environment variables:
|
||||||
|
|
||||||
* `ETHERPAD_TITLE`: Title of the Etherpad Lite instance. Defaults to "Etherpad".
|
* `ETHERPAD_TITLE`: Title of the Etherpad Lite instance. Defaults to "Etherpad".
|
||||||
* `ETHERPAD_PORT`: Port of the Etherpad Lite instance. Defaults to 9001.
|
* `ETHERPAD_PORT`: Port of the Etherpad Lite instance. Defaults to 9001.
|
||||||
|
* `ETHERPAD_SESSION_KEY`: Session key for the Etherpad Lite configuraition. You
|
||||||
|
can set this in case of migrating from another installation. A value is
|
||||||
|
automatically generated by default.
|
||||||
|
|
||||||
* `ETHERPAD_ADMIN_PASSWORD`: If set, an admin account is enabled for Etherpad,
|
* `ETHERPAD_ADMIN_PASSWORD`: If set, an admin account is enabled for Etherpad,
|
||||||
and the /admin/ interface is accessible via it.
|
and the /admin/ interface is accessible via it.
|
||||||
|
@ -72,7 +65,7 @@ Otherwise the user can set it to another username.
|
||||||
* `ETHERPAD_DB_HOST`: Hostname of the mysql databse to use. Defaults to `mysql`
|
* `ETHERPAD_DB_HOST`: Hostname of the mysql databse to use. Defaults to `mysql`
|
||||||
* `ETHERPAD_DB_USER`: By default Etherpad Lite will attempt to connect as root
|
* `ETHERPAD_DB_USER`: By default Etherpad Lite will attempt to connect as root
|
||||||
to the mysql container.
|
to the mysql container.
|
||||||
* `ETHERPAD_DB_PASS`: MySQL password to use, mandatory. If legacy links
|
* `ETHERPAD_DB_PASSWORD`: MySQL password to use, mandatory. If legacy links
|
||||||
are used and ETHERPAD_DB_USER is root, then `MYSQL_ENV_MYSQL_ROOT_PASSWORD` is
|
are used and ETHERPAD_DB_USER is root, then `MYSQL_ENV_MYSQL_ROOT_PASSWORD` is
|
||||||
automatically used.
|
automatically used.
|
||||||
* `ETHERPAD_DB_NAME`: The mysql database to use. Defaults to *etherpad*. If the
|
* `ETHERPAD_DB_NAME`: The mysql database to use. Defaults to *etherpad*. If the
|
||||||
|
@ -80,4 +73,3 @@ database is not available, it will be created when the container is launched.
|
||||||
|
|
||||||
The generated settings.json file will be available as a volume under
|
The generated settings.json file will be available as a volume under
|
||||||
*/opt/etherpad-lite/var/*.
|
*/opt/etherpad-lite/var/*.
|
||||||
|
|
||||||
|
|
|
@ -4,25 +4,23 @@ version: "3.4"
|
||||||
services:
|
services:
|
||||||
db:
|
db:
|
||||||
image: mariadb:10.3
|
image: mariadb:10.3
|
||||||
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
|
|
||||||
volumes:
|
volumes:
|
||||||
- db_data:/var/lib/mysql
|
- db_data:/var/lib/mysql
|
||||||
environment:
|
environment:
|
||||||
MARIADB_ROOT_PASSWORD: insecure
|
MYSQL_ROOT_PASSWORD: insecure
|
||||||
MARIADB_DATABASE: etherpad
|
MYSQL_DATABASE: etherpad
|
||||||
|
|
||||||
etherpad:
|
etherpad:
|
||||||
build:
|
build: .
|
||||||
context: .
|
|
||||||
dockerfile: Dockerfile
|
|
||||||
image: glenux/etherpad:latest
|
|
||||||
environment:
|
environment:
|
||||||
DATABASE_URL: mysql://root:insecure:3306@db/etherpad
|
DATABASE_URL: mysql://root:insecure@db/etherpad
|
||||||
ETHERPAD_ADMIN_USER: admin
|
ETHERPAD_ADMIN_USER: admin
|
||||||
ETHERPAD_ADMIN_PASSWORD: insecure
|
ETHERPAD_ADMIN_PASSWORD: insecure
|
||||||
NODE_ENV: production
|
NODE_ENV: production
|
||||||
ports:
|
ports:
|
||||||
- 9001:9001
|
- "9001:9001"
|
||||||
|
depends_on:
|
||||||
|
- "db"
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
db_data: {}
|
db_data: {}
|
||||||
|
|
44
entrypoint.sh
Executable file → Normal file
44
entrypoint.sh
Executable file → Normal file
|
@ -1,27 +1,30 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
set -e
|
set -e
|
||||||
|
|
||||||
eval "$(sh /parseurl.sh "$DATABASE_URL" ETHERPAD_DB)"
|
chmod +x /parseurl.py
|
||||||
|
/parseurl.py ETHERPAD_DB_
|
||||||
|
eval "$(/parseurl.py ETHERPAD_DB_)"
|
||||||
|
|
||||||
# ETHERPAD_DB_PASS is mandatory in mysql container, so we're not offering
|
# 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
|
# 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_USER" = 'root' ]; then
|
# if [ "$ETHERPAD_DB_USERNAME" = 'root' ]; then
|
||||||
# : ${ETHERPAD_DB_PASS:=$MYSQL_ENV_MYSQL_ROOT_PASSWORD}
|
# : ${ETHERPAD_DB_PASSWORD:=$MYSQL_ENV_MYSQL_ROOT_PASSWORD}
|
||||||
# fi
|
# fi
|
||||||
|
|
||||||
if [ -z "$ETHERPAD_DB_USER" ]; then
|
if [ -z "$ETHERPAD_DB_USERNAME" ]; then
|
||||||
echo >&2 'error: missing required ETHERPAD_DB_USER environment variable'
|
echo >&2 'error: missing required ETHERPAD_DB_USERNAME environment variable'
|
||||||
echo >&2 ' Did you forget to -e ETHERPAD_DB_USER=... ?'
|
echo >&2 ' Did you forget to -e ETHERPAD_DB_USERNAME=... ?'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$ETHERPAD_DB_PASS" ]; then
|
if [ -z "$ETHERPAD_DB_PASSWORD" ]; then
|
||||||
echo >&2 'error: missing required ETHERPAD_DB_PASS environment variable'
|
echo >&2 'error: missing required ETHERPAD_DB_PASSWORD environment variable'
|
||||||
echo >&2 ' Did you forget to -e ETHERPAD_DB_PASS=... ?'
|
echo >&2 ' Did you forget to -e ETHERPAD_DB_PASSWORD=... ?'
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
RANDOM_STRING="$(node -p "require('crypto').randomBytes(32).toString('hex')")}"
|
||||||
|
|
||||||
# Sanitize DB information
|
# Sanitize DB information
|
||||||
ETHERPAD_DB_HOST="${ETHERPAD_DB_HOST:-}"
|
ETHERPAD_DB_HOST="${ETHERPAD_DB_HOST:-}"
|
||||||
|
@ -29,6 +32,7 @@ ETHERPAD_DB_PORT="${ETHERPAD_DB_PORT:-3306}"
|
||||||
|
|
||||||
# Sanitize etherpad info
|
# Sanitize etherpad info
|
||||||
ETHERPAD_PORT="${ETHERPAD_PORT:-9001}"
|
ETHERPAD_PORT="${ETHERPAD_PORT:-9001}"
|
||||||
|
ETHERPAD_SESSION_KEY="${ETHERPAD_SESSION_KEY:-$RANDOM_STRING}"
|
||||||
ETHERPAD_TITLE="${ETHERPAD_TITLE:-Etherpad}"
|
ETHERPAD_TITLE="${ETHERPAD_TITLE:-Etherpad}"
|
||||||
|
|
||||||
# Wait for database
|
# Wait for database
|
||||||
|
@ -43,8 +47,8 @@ sleep 1
|
||||||
|
|
||||||
# Check if database already exists
|
# Check if database already exists
|
||||||
RESULT="$(mysql \
|
RESULT="$(mysql \
|
||||||
"-u${ETHERPAD_DB_USER}" \
|
"-u${ETHERPAD_DB_USERNAME}" \
|
||||||
"-p${ETHERPAD_DB_PASS}" \
|
"-p${ETHERPAD_DB_PASSWORD}" \
|
||||||
"-P${ETHERPAD_DB_PORT}" \
|
"-P${ETHERPAD_DB_PORT}" \
|
||||||
"-h${ETHERPAD_DB_HOST}" \
|
"-h${ETHERPAD_DB_HOST}" \
|
||||||
--skip-column-names \
|
--skip-column-names \
|
||||||
|
@ -54,8 +58,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_USER}" \
|
mysql "-u${ETHERPAD_DB_USERNAME}" \
|
||||||
"-p${ETHERPAD_DB_PASS}" \
|
"-p${ETHERPAD_DB_PASSWORD}" \
|
||||||
"-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}"
|
||||||
|
@ -69,14 +73,12 @@ if ! [ -f settings.json ]; then
|
||||||
"ip": "0.0.0.0",
|
"ip": "0.0.0.0",
|
||||||
"port" :${ETHERPAD_PORT},
|
"port" :${ETHERPAD_PORT},
|
||||||
"skinName": "colibris",
|
"skinName": "colibris",
|
||||||
"trustProxy" : false,
|
"sessionKey" : "${ETHERPAD_SESSION_KEY}",
|
||||||
"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",
|
"dbType" : "mysql",
|
||||||
"dbSettings" : {
|
"dbSettings" : {
|
||||||
"user" : "${ETHERPAD_DB_USER}",
|
"user" : "${ETHERPAD_DB_USERNAME}",
|
||||||
"host" : "${ETHERPAD_DB_HOST}",
|
"host" : "${ETHERPAD_DB_HOST}",
|
||||||
"password": "${ETHERPAD_DB_PASS}",
|
"password": "${ETHERPAD_DB_PASSWORD}",
|
||||||
"database": "${ETHERPAD_DB_NAME}"
|
"database": "${ETHERPAD_DB_NAME}"
|
||||||
},
|
},
|
||||||
EOF
|
EOF
|
||||||
|
@ -96,10 +98,6 @@ EOF
|
||||||
fi
|
fi
|
||||||
|
|
||||||
cat <<- EOF >> settings.json
|
cat <<- EOF >> settings.json
|
||||||
"ep_expiration" : {
|
|
||||||
"enabled": true,
|
|
||||||
"max_days": 30
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
fi
|
fi
|
||||||
|
|
63
parseurl.py
Executable file
63
parseurl.py
Executable file
|
@ -0,0 +1,63 @@
|
||||||
|
#!/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
35
parseurl.sh
|
@ -1,35 +0,0 @@
|
||||||
#!/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