-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdocker-entrypoint.sh
More file actions
82 lines (73 loc) · 2.23 KB
/
docker-entrypoint.sh
File metadata and controls
82 lines (73 loc) · 2.23 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/bin/sh
set -e
PUID="${PUID:-}"
PGID="${PGID:-}"
CONFIG_PATH="${SORTARR_CONFIG_PATH:-${ENV_FILE_PATH:-/config/Sortarr.env}}"
is_number() {
case "$1" in
''|*[!0-9]*) return 1 ;;
*) return 0 ;;
esac
}
if [ -n "$PUID" ] && [ -n "$PGID" ]; then
if ! is_number "$PUID" || ! is_number "$PGID"; then
echo "PUID/PGID must be numeric; running as root." >&2
exec "$@"
fi
group_name="sortarr"
if getent group "$PGID" >/dev/null 2>&1; then
group_name="$(getent group "$PGID" | cut -d: -f1)"
else
if command -v groupadd >/dev/null 2>&1; then
groupadd -g "$PGID" "$group_name"
elif command -v addgroup >/dev/null 2>&1; then
addgroup --gid "$PGID" "$group_name"
fi
fi
user_name="sortarr"
if getent passwd "$PUID" >/dev/null 2>&1; then
user_name="$(getent passwd "$PUID" | cut -d: -f1)"
else
if command -v useradd >/dev/null 2>&1; then
useradd -u "$PUID" -g "$PGID" -s /bin/sh -M "$user_name"
elif command -v adduser >/dev/null 2>&1; then
adduser --uid "$PUID" --gid "$PGID" --disabled-password --gecos "" "$user_name"
fi
fi
safe_chown() {
dir_path="$1"
if [ -n "$dir_path" ]; then
mkdir -p "$dir_path"
chown -R "$PUID:$PGID" "$dir_path" 2>/dev/null || true
fi
}
if [ -d "/config" ]; then
safe_chown "/config"
fi
for path in \
"$CONFIG_PATH" \
"$ENV_FILE_PATH" \
"$TAUTULLI_METADATA_CACHE" \
"$SONARR_CACHE_PATH" \
"$RADARR_CACHE_PATH" \
"$PLEX_CACHE_PATH" \
"$JELLYFIN_CACHE_PATH" \
"$JELLYSTAT_CACHE_PATH" \
"$STREAMYSTATS_CACHE_PATH"; do
if [ -n "$path" ]; then
safe_chown "$(dirname "$path")"
fi
done
safe_chown "$(dirname "$CONFIG_PATH")/secrets"
if [ "$PUID" != "0" ] || [ "$PGID" != "0" ]; then
if command -v gosu >/dev/null 2>&1; then
exec gosu "$user_name" "$@"
fi
if command -v su-exec >/dev/null 2>&1; then
exec su-exec "$user_name" "$@"
fi
echo "gosu/su-exec not available; running as root." >&2
exec "$@"
fi
fi
exec "$@"