-
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathdocker_entry.sh
More file actions
executable file
·51 lines (42 loc) · 1.58 KB
/
Copy pathdocker_entry.sh
File metadata and controls
executable file
·51 lines (42 loc) · 1.58 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
#!/bin/sh
set -e
if [[ -z "$REDIS_HOST" ]]; then
echo "Starting redis"
/redis/redis-server --dir /config &
fi
PUID=${PUID:-1000}
PGID=${PGID:-1000}
USERNAME="iplayarr"
echo "Starting container with UID:$PUID and GID:$PGID"
EXISTING_GROUP=$(getent group "$PGID" | cut -d: -f1)
if [ -z "$EXISTING_GROUP" ]; then
GROUPNAME="$USERNAME"
addgroup -g "$PGID" "$GROUPNAME"
else
GROUPNAME="$EXISTING_GROUP"
fi
EXISTING_USER=$(getent passwd "$PUID" | cut -d: -f1)
if [ -z "$EXISTING_USER" ]; then
adduser -D -u "$PUID" -G "$GROUPNAME" "$USERNAME"
EXISTING_USER="$USERNAME"
fi
if [ -n "$STORAGE_LOCATION" ] && [ -d "$STORAGE_LOCATION" ]; then
chown -R "${EXISTING_USER}":"${GROUPNAME}" "${STORAGE_LOCATION}" || { echo "Failed to change ownership of ${STORAGE_LOCATION} to ${PUID}:${PGID}"; exit 1; }
else
echo "STORAGE_LOCATION is not set or does not exist"
exit 1
fi
if [ -n "$CACHE_LOCATION" ] && [ -d "$CACHE_LOCATION" ]; then
chown -R "${EXISTING_USER}":"${GROUPNAME}" "${CACHE_LOCATION}" || { echo "Failed to change ownership of ${CACHE_LOCATION} to ${PUID}:${PGID}"; exit 1; }
else
echo "CACHE_LOCATION is not set or does not exist"
exit 1
fi
if [ -n "$LOG_DIR" ] && [ -d "$LOG_DIR" ]; then
chown -R "${EXISTING_USER}":"${GROUPNAME}" "${LOG_DIR}" || { echo "Failed to change ownership of ${LOG_DIR} to ${PUID}:${PGID}"; exit 1; }
else
echo "LOG_DIR is not set or does not exist"
exit 1
fi
find /app -name "node_modules" -prune -o \! -user "$PUID" \! -group "$PGID" -exec chown "${EXISTING_USER}":"${GROUPNAME}" {} +
exec su-exec "$EXISTING_USER" "$@"