aboutsummaryrefslogtreecommitdiff
path: root/moin/entrypoint.sh
blob: 6792c18a74b1124fd9459d9c1d2b2e72810fe50e (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
#!/bin/sh

set -e -x

export PATH="/usr/bin:$PATH"
export PYTHONPATH="/srv/wiki-common/config"

# Allow users to specify the UID/GID in the environment but
# default these to the existing owner of the files in their
# mounted config, which should be sane.
DATA_DIR="/srv/wiki/data"
if [[ -d "$DATA_DIR" ]]; then
    WIKIUID=${WIKIUID:-$(stat -c "%u" $DATA_DIR)}
    WIKIGID=${WIKIGID:-$(stat -c "%u" $DATA_DIR)}

    addgroup -g ${WIKIGID} -S wiki
    adduser -u ${WIKIUID} -S -H -D -G wiki wiki
else
    echo "No data directory found"
    # This may be a debug session if a shell was requested otherwise it's a
    # hard failure
    if [[ "$1" != "/bin/sh" ]]; then
        exit 1
    fi
fi

if [[ "$1" == "/bin/sh" ]]; then
    exec "$@"
fi

if [[ ! -d "/srv/wiki/data/cache/xapian/index" ]]; then
    /sbin/su-exec wiki:wiki \
        moin --config-dir /srv/wiki/config index build --mode=rebuild
fi

exec "$@"