-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
executable file
·132 lines (106 loc) · 3.26 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#!/bin/bash
set -e
if [ -z "$MYSQL_PORT_3306_TCP_ADDR" ]; then
echo >&2 'error: missing MYSQL_PORT_3306_TCP environment variable'
echo >&2 ' Did you forget to --link some_mysql_container:mysql ?'
exit 1
fi
# if we're linked to MySQL, and we're using the root user, and our linked
# container has a default "root" password set up and passed through... :)
: ${ETHERPAD_DB_USER:=root}
if [ "$ETHERPAD_DB_USER" = 'root' ]; then
: ${ETHERPAD_DB_PASSWORD:=$MYSQL_ENV_MYSQL_ROOT_PASSWORD}
fi
: ${ETHERPAD_DB_NAME:=etherpad}
ETHERPAD_DB_NAME=$( echo $ETHERPAD_DB_NAME | sed 's/\./_/g' )
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=... ?'
echo >&2
echo >&2 ' (Also of interest might be ETHERPAD_DB_USER and ETHERPAD_DB_NAME.)'
exit 1
fi
: ${ETHERPAD_TITLE:=Etherpad}
: ${ETHERPAD_PORT:=9001}
: ${ETHERPAD_SESSION_KEY:=$(
node -p "require('crypto').randomBytes(32).toString('hex')")}
# Check if database already exists
# RESULT=`mysql -u${ETHERPAD_DB_USER} -p${ETHERPAD_DB_PASSWORD} \
# -hmysql --skip-column-names \
# -e "SHOW DATABASES LIKE '${ETHERPAD_DB_NAME}'"`
#
# if [ "$RESULT" != $ETHERPAD_DB_NAME ]; then
# # mysql database does not exist, create it
# echo "Creating database ${ETHERPAD_DB_NAME}"
#
# mysql -u${ETHERPAD_DB_USER} -p${ETHERPAD_DB_PASSWORD} -hmysql \
# -e "create database ${ETHERPAD_DB_NAME}"
# fi
npm install ep_hash_auth
if [ ! -f settings.json ]; then
cat <<- EOF > settings.json
{
"title": "${ETHERPAD_TITLE}",
"ip": "0.0.0.0",
"port" :${ETHERPAD_PORT},
"sessionKey" : "${ETHERPAD_SESSION_KEY}",
"dbType" : "mysql",
"dbSettings" : {
"user" : "${ETHERPAD_DB_USER}",
"host" : "mysql",
"password": "${ETHERPAD_DB_PASSWORD}",
"database": "${ETHERPAD_DB_NAME}"
},
EOF
if [ $ETHERPAD_PLUGINS ]; then
for plugin in $(echo "${ETHERPAD_PLUGINS//,/
}"); do
[ -d node_modules/$plugin ] || npm install $plugin
VARNAME=$(echo $plugin | tr '[[:lower:]]' '[[:upper:]]')
VARNAME="${VARNAME}_CONFIG"
eval plugin_config=\$$VARNAME
if [ $plugin_config ]; then
echo " $plugin_config," >> settings.json
fi
done
fi
if [ $ETHERPAD_ADMIN_ACCOUNTS ]; then
cat <<- EOF >> settings.json
"users": {
EOF
for account in $(echo "${ETHERPAD_ADMIN_ACCOUNTS//:/
}"); do
IFS='=' read user pass admin <<<$(echo "$account")
echo "ACCT = $account"
echo "U/P = $user : $pass : $admin"
hashedpass=$(echo -n "$pass" | sha512sum | cut -d' ' -f1)
admin=${admin:-false}
echo "final admin = $admin"
cat <<- EOF >> settings.json
"$user": {
"hash": "$hashedpass",
"is_admin": $admin
},
EOF
done
echo " }" >> settings.json
elif [ $ETHERPAD_ADMIN_PASSWORD ]; then
: ${ETHERPAD_ADMIN_HASHEDPASSWORD:=$(
echo -n "$ETHERPAD_ADMIN_PASSWORD" | sha512sum | cut -d' ' -f1
)}
: ${ETHERPAD_ADMIN_USER:=admin}
cat <<- EOF >> settings.json
"ep_hash_auth": { "hash_typ": "sha512", "hash_dig": "hex" },
"users": {
"${ETHERPAD_ADMIN_USER}": {
"hash": "${ETHERPAD_ADMIN_HASHEDPASSWORD}",
"is_admin": true
}
}
EOF
fi
cat <<- EOF >> settings.json
}
EOF
fi
exec "$@"