-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint
51 lines (39 loc) · 1.88 KB
/
entrypoint
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
#!/bin/bash
set -e
LOCAL_CONF_FILE=/usr/local/studip/config/config_local.inc.php
if [ -z "$STUDIP_CONF_DB_STUDIP_HOST"] && [ -n "$MYSQL_PORT_3306_TCP_ADDR" ]; then
export STUDIP_CONF_DB_STUDIP_HOST="$MYSQL_PORT_3306_TCP_ADDR"
fi
if [ -z "$STUDIP_CONF_DB_STUDIP_USER"] && [ -n "$MYSQL_ENV_MYSQL_USER" ]; then
export STUDIP_CONF_DB_STUDIP_USER="$MYSQL_ENV_MYSQL_USER"
fi
if [ -z "$STUDIP_CONF_DB_STUDIP_PASSWORD"] && [ -n "$MYSQL_ENV_MYSQL_PASSWORD" ]; then
export STUDIP_CONF_DB_STUDIP_PASSWORD="$MYSQL_ENV_MYSQL_PASSWORD"
fi
if [ -z "$STUDIP_CONF_DB_STUDIP_DATABASE"] && [ -n "$MYSQL_ENV_MYSQL_DATABASE" ]; then
export STUDIP_CONF_DB_STUDIP_DATABASE="$MYSQL_ENV_MYSQL_DATABASE"
fi
#Interpret all vars starting with $prefix as variables in $LOCAL_CONF_FILE and replace them
prefix="STUDIP_CONF"
eval 'vars=(${!'"$prefix"'@})'
for var in ${vars[@]}; do
var_val=${!var}
var_name=${var#"$prefix"_}
if $(grep -q "$var_name" "$LOCAL_CONF_FILE"); then
sed -i "s/\$$var_name = .*/\$$var_name = \"$var_val\";/g" $LOCAL_CONF_FILE
else
echo '\$$var_name = "$var_val"' >> $LOCAL_CONF_FILE
fi
done
if [ "$1" == "initdb" ]; then
mysql --host="$STUDIP_CONF_DB_STUDIP_HOST" --user="$STUDIP_CONF_DB_STUDIP_USER" --password="$STUDIP_CONF_DB_STUDIP_PASSWORD" "$STUDIP_CONF_DB_STUDIP_DATABASE" < /usr/local/studip/db/studip.sql
mysql --host="$STUDIP_CONF_DB_STUDIP_HOST" --user="$STUDIP_CONF_DB_STUDIP_USER" --password="$STUDIP_CONF_DB_STUDIP_PASSWORD" "$STUDIP_CONF_DB_STUDIP_DATABASE" < /usr/local/studip/db/studip_default_data.sql
mysql --host="$STUDIP_CONF_DB_STUDIP_HOST" --user="$STUDIP_CONF_DB_STUDIP_USER" --password="$STUDIP_CONF_DB_STUDIP_PASSWORD" "$STUDIP_CONF_DB_STUDIP_DATABASE" < /usr/local/studip/db/studip_root_user.sql
/usr/local/studip/cli/migrate.php
exit 0
fi
# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- apache2-foreground "$@"
fi
exec "$@"