aboutsummaryrefslogtreecommitdiff
path: root/dropbox/entrypoint.sh
blob: 596cac6c0fe730d42cbc37d723a49723bf6f0eab (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
#!/bin/sh

set -e

DATA_DIR="/srv/dropbox/data"
CFG_DIR="/srv/dropbox/config"
USERNAME="dropbox"

# Default UID/GID to owner of the data directory
USER_UID=${USER_UID:-$(stat -L -c "%u" $DATA_DIR)}
USER_GID=${USER_GID:-$(stat -L -c "%u" $DATA_DIR)}

if [ "$USER_GID" = 0 -o "$USER_GID" = 0 ]; then
    echo "User UID/GID could not be discovered, is $DATA_DIR mounted?"
    exit 1
fi

# Create the user and group
addgroup -g ${USER_GID} -S ${USERNAME}
adduser -u ${USER_UID} -h /home/${USERNAME} -D -G ${USERNAME} ${USERNAME}

ln -s /srv/dropbox/data /home/${USERNAME}/Dropbox
ln -s /srv/dropbox/config /home/${USERNAME}/.dropbox

# Allow runsv to write its superisory files for the main process
mkdir /opt/dropbox-srv/supervise
chown dropbox:dropbox /opt/dropbox-srv/supervise

# Allow runsv to write its superisory files for the log process
mkdir /opt/dropbox-srv/log/supervise
chown dropbox:dropbox /opt/dropbox-srv/log/supervise

if [ "$@" == "/bin/sh" ]; then
    exec "$@"
else
    exec /usr/bin/dumb-init -c /sbin/su-exec ${USERNAME} "$@"
fi