aboutsummaryrefslogtreecommitdiff
path: root/docker/studip/docker-entrypoint.sh
blob: 4432d275b2c227e1aa0065343b62f39d9afc098f (plain)
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
#!/bin/bash
set -e

for dir in \
    /var/www/studip/data/upload_doc \
    /var/www/studip/data/assets_cache \
    /var/www/studip/data/media_cache \
    /var/www/studip/public/pictures \
    /var/www/studip/public/plugins_packages
do
    mkdir -p "$dir"
    chown -R www-data:www-data "$dir"
    chmod -R u+rwX,g+rwX "$dir"
done

mysql_client_args=(--skip-ssl -u "$MYSQL_USER" -h "$MYSQL_HOST" "-p$MYSQL_PASSWORD")

STUDIP='/var/www/studip'
CONFIGFILE="$STUDIP/config/config_local.inc.php"
DOCKERCONFIGFILE="/config/config_local.inc.php"
CONF="$STUDIP/config/config.inc.php"

# Check if we have a config
if [ ! -f $CONFIGFILE ]; then
    echo "Setting up new config"
    cp "$DOCKERCONFIGFILE" "$CONFIGFILE"
    cp "$CONF.dist" "$CONF"
fi

# wait until MySQL is really available
maxcounter=45

counter=1
while ! mysql "${mysql_client_args[@]}" -e "show databases;" > /dev/null 2>&1; do
    sleep 1
    counter=`expr $counter + 1`
    if [ $counter -gt $maxcounter ]; then
        echo "We have been waiting for MySQL too long already; failing." >&2
        exit 1
    fi;
done

sh $STUDIP/.gitlab/scripts/install_db.sh

if [[ -n $AUTO_MIGRATE ]]; then
    echo "Migrate Instance"
    # If migrate fails start instance anyway
    php "$STUDIP/cli/studip" migrate || true
    echo "Migration finished"
fi

# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
    set -- apache2-foreground "$@"
fi

# Set name of installation if set
if [[ -n "$STUDIP_NAME" ]]; then
    echo "Setting installation name"
    php "$STUDIP/cli/studip" config:set UNI_NAME_CLEAN "$STUDIP_NAME"
fi

exec "$@"