summaryrefslogtreecommitdiffstats
path: root/2.4/docker-entrypoint.sh
blob: d565765a342ff93c261d1a71d56831188e476729 (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
#!/bin/sh
set -e

# Add password hash, unless "user.passwd" already exists (ie, bind mounted).
REALM="WebDAV"
if [ ! -e "/tmp/conf/user.passwd" ]; then
    touch "/tmp/conf/user.passwd"
    # Only generate a password hash if both username and password given.
    if [ "x$USERNAME" != "x" ] && [ "x$PASSWORD" != "x" ]; then
        if [ "$AUTH_TYPE" = "Digest" ]; then
            # Can't run `htdigest` non-interactively, so use other tools.
            HASH="`printf '%s' "$USERNAME:$REALM:$PASSWORD" | md5sum | awk '{print $1}'`"
            printf '%s\n' "$USERNAME:$REALM:$HASH" > /tmp/user.passwd
        else
            htpasswd -B -b -c "/tmp/conf/user.passwd" $USERNAME $PASSWORD
        fi
    fi
fi

# If specified, allow anonymous access to specified methods.
if [ "x$ANONYMOUS_METHODS" != "x" ]; then
    if [ "$ANONYMOUS_METHODS" = "ALL" ]; then
        sed -e "s/Require valid-user/Require all granted/" \
            -i "/tmp/conf/conf-available/dav.conf"
    else
        ANONYMOUS_METHODS="`printf '%s\n' "$ANONYMOUS_METHODS" | tr ',' ' '`"
        sed -e "/Require valid-user/a\ \ \ \ Require method $ANONYMOUS_METHODS" \
            -i "/tmp/conf/conf-available/dav.conf"
    fi
fi

# Create directories for Dav data and lock database.
[ ! -d "/var/dav/data" ] && mkdir -p "/var/dav/data"
[ ! -e "/tmp/DavLock" ] && touch "/tmp/DavLock"


if ! whoami &> /dev/null; then
  if [ -w /etc/passwd ]; then
    echo "${USER_NAME:-default}:x:$(id -u):0:${USER_NAME:-default} user:${HOME}:/sbin/nologin" >> /etc/passwd
  fi
fi

exec "$@"