-
Notifications
You must be signed in to change notification settings - Fork 0
/
entrypoint.sh
49 lines (40 loc) · 1.23 KB
/
entrypoint.sh
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
#!/bin/bash
set -e
if [ ! -z "${DEBUG}" ]; then
set -x
fi
CURRENT_UID=$(id -u)
if [[ ${CURRENT_UID} != 0 ]]; then
echo "[WARN] Host UID/GID usage disabled because the container is not running under the root (current uid: ${CURRENT_UID})"
exec "$@"
exit
fi
# we find the host uid/gid by assuming the app directory belongs to the host
if [ -z "${HOST_UID}" ]; then
HOST_UID=$(stat -c %u /utorrent/data)
fi
if [ -z "${HOST_GID}" ]; then
HOST_GID=$(stat -c %g /utorrent/data)
fi
DO_CHOWN=0
# If the docker user doesn't share the same uid, change it so that it does
if [ ! "${HOST_UID}" = "$(id -u utorrent)" ] && [[ ${HOST_UID} != 0 ]]; then
usermod -o -u ${HOST_UID} utorrent
DO_CHOWN=1
fi
if [ ! "${HOST_GID}" = "$(id -g utorrent)" ] && [[ ${HOST_GID} != 0 ]]; then
groupmod -o -g ${HOST_GID} utorrent
DO_CHOWN=1
fi
# also update the file uid/gid for files in the docker home directory
# skip the mounted "app" dir because we don't want any changes to mounted file ownership
if [[ ${DO_CHOWN} != 0 ]]; then
shopt -s dotglob
for file in /utorrent/*; do
if [ $file != "/utorrent/utserver" ]; then
chown -R utorrent:utorrent $file
fi
done
fi
exec sudo -u utorrent -g utorrent -- "$@"
#exec "$@" su utorrent