-
Notifications
You must be signed in to change notification settings - Fork 2
/
docker-entrypoint.sh
72 lines (56 loc) · 2.5 KB
/
docker-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
#!/bin/bash
set -e
: ${HOST_USER_ID:=""}
: ${URL_PREFIX:="/"}
: ${COOKIE_SECRET:=""}
: ${MAX_LOG_SIZE:="100000000"}
: ${MAX_LOG_BACKUPS:="10"}
: ${SESSION_TIMEOUT:="30m"}
fix_permission() {
echo "Fixing permissions..."
if [ "$HOST_USER_ID" != "" ]; then
# based on https://github.com/schmidigital/permission-fix/blob/master/tools/permission_fix
UNUSED_USER_ID=21338
# Setting User Permissions
DOCKER_USER_CURRENT_ID=`id -u $GATEONE_USER`
if [ "$DOCKER_USER_CURRENT_ID" != "$HOST_USER_ID" ]; then
DOCKER_USER_OLD=`getent passwd $HOST_USER_ID | cut -d: -f1`
if [ ! -z "$DOCKER_USER_OLD" ]; then
usermod -o -u $UNUSED_USER_ID $DOCKER_USER_OLD
fi
usermod -o -u $HOST_USER_ID $GATEONE_USER || true
fi
fi
chown -R $GATEONE_USER $GATEONE_HOME
}
init() {
if [ ! -d $GATEONE_HOME/venv ]; then
echo "Initializing..."
exec /sbin/setuser $GATEONE_USER ./install_gateone.sh &
for job in `jobs -p`
do
wait $job || echo "Faild to wait job $job."
done
if [ "$COOKIE_SECRET" != "" ]; then
sed -i -e 's|\("cookie_secret":\) .*|\1 "'"$COOKIE_SECRET"'",|' $GATEONE_HOME/.gateone/conf.d/10server.conf
fi
sed -i -e 's|\("url_prefix":\) .*|\1 "'"$URL_PREFIX"'",|' $GATEONE_HOME/.gateone/conf.d/10server.conf \
&& sed -i -e 's|\("js_init":\) .*|\1 "{'"'theme': 'white'"'}",|' $GATEONE_HOME/.gateone/conf.d/10server.conf \
&& sed -i -e 's|\("user_dir":\) .*|\1 "'"$GATEONE_HOME"'/.gateone/users",|' $GATEONE_HOME/.gateone/conf.d/10server.conf \
&& sed -i -e 's|\("log_to_stderr":\) .*|\1 false,|' $GATEONE_HOME/.gateone/conf.d/10server.conf \
&& sed -i -e 's|\("multiprocessing_workers":\) .*|\1 '"$((`lscpu | grep 'Socket(s)' | awk '{ print $(NF) }'` * `lscpu | grep 'Core(s)' | awk '{ print $(NF)}'` * `lscpu | grep 'Thread(s)' | awk '{ print $(NF)}'` + 1))"',|' $GATEONE_HOME/.gateone/conf.d/10server.conf \
&& sed -i -e 's|\("log_file_max_size":\) .*|\1 '"$MAX_LOG_SIZE"',|' $GATEONE_HOME/.gateone/conf.d/10server.conf \
&& sed -i -e 's|\("log_file_num_backups":\) .*|\1 '"$MAX_LOG_BACKUPS"',|' $GATEONE_HOME/.gateone/conf.d/10server.conf \
&& sed -i -e 's|\("session_timeout":\) .*|\1 "'"$SESSION_TIMEOUT"'",|' $GATEONE_HOME/.gateone/conf.d/10server.conf \
&& sed -i -e "s|--sshfp -a '|-a '-oStrictHostKeychecking=no |" $GATEONE_HOME/.gateone/conf.d/50terminal.conf
fi
}
# start GateOne
if [ "$1" = 'gateone' ]; then
fix_permission
init
# now start GateOne
echo "Starting GateOne..."
exec /sbin/setuser $GATEONE_USER /gateone/venv/bin/gateone > /dev/null 2>&1
fi
exec "$@"