-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathentrypoint.sh
More file actions
83 lines (70 loc) · 3.64 KB
/
Copy pathentrypoint.sh
File metadata and controls
83 lines (70 loc) · 3.64 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
83
#!/bin/sh
set -e
# ──────────────────────────────────────────────────────────────
# PUID / PGID handling (LinuxServer.io / *-arr convention)
# Allows the container to run with the host user's UID/GID
# so that mounted volumes have correct ownership.
# ──────────────────────────────────────────────────────────────
PUID=${PUID:-1000}
PGID=${PGID:-1000}
UMASK=${UMASK:-022}
echo "───────────────────────────────────────"
echo " Questarr — Starting container"
echo " PUID: ${PUID}"
echo " PGID: ${PGID}"
echo " UMASK: ${UMASK}"
echo "───────────────────────────────────────"
umask "$UMASK"
# Adjust the questarr group GID if it differs from PGID
CURRENT_GID=$(id -g questarr)
if [ "$CURRENT_GID" != "$PGID" ]; then
echo "Updating questarr group GID from ${CURRENT_GID} to ${PGID}"
groupmod -o -g "$PGID" questarr
fi
# Adjust the questarr user UID if it differs from PUID
CURRENT_UID=$(id -u questarr)
if [ "$CURRENT_UID" != "$PUID" ]; then
echo "Updating questarr user UID from ${CURRENT_UID} to ${PUID}"
usermod -o -u "$PUID" questarr
fi
# Ensure the data directory exists and key directories are owned by the correct user
mkdir -p /app/data
QUESTARR_UID=$(id -u questarr)
QUESTARR_GID=$(id -g questarr)
# Only chown /app if ownership does not already match (avoids failures on NFS with root squash)
APP_OWNER_UID=$(stat -c '%u' /app)
APP_OWNER_GID=$(stat -c '%g' /app)
if [ "$APP_OWNER_UID" != "$QUESTARR_UID" ] || [ "$APP_OWNER_GID" != "$QUESTARR_GID" ]; then
echo "Setting ownership of /app to questarr:questarr"
chown questarr:questarr /app
fi
# Only chown /app/data if the directory itself or any nested file/dir has wrong ownership.
# Scanning recursively catches post-restore trees where the top-level inode matches but
# inner files were created by a different host UID/GID.
# -print -quit stops at the first mismatch so this is fast even on large trees.
if find /app/data \( ! -uid "$QUESTARR_UID" -o ! -gid "$QUESTARR_GID" \) -print -quit 2>/dev/null | grep -q .; then
echo "Setting ownership of /app/data to questarr:questarr"
chown -R questarr:questarr /app/data
fi
# Verify the questarr user can actually write to /app/data before dropping privileges.
# If this fails, the DB would crash at startup with an unhelpful SQLite error.
if ! su-exec questarr test -w /app/data 2>/dev/null; then
echo "ERROR: questarr (UID ${QUESTARR_UID}) cannot write to /app/data."
echo " The chown above may have failed due to filesystem restrictions (e.g. rootless Docker, NFS)."
echo " Fix on the host: sudo chown -R ${QUESTARR_UID}:${QUESTARR_GID} ./data"
echo " Or match the data directory's owner by setting PUID/PGID in your compose environment."
exit 1
fi
# If the database file already exists, verify it is writable too.
# A recursive chown on the directory won't help if the file itself has a mode like 400.
if [ -z "$SQLITE_DB_PATH" ]; then
export SQLITE_DB_PATH="/app/data/sqlite.db"
fi
_DB_FILE="$SQLITE_DB_PATH"
if [ -f "$_DB_FILE" ] && ! su-exec questarr test -w "$_DB_FILE" 2>/dev/null; then
echo "ERROR: questarr (UID ${QUESTARR_UID}) cannot write to existing database file ${_DB_FILE}."
echo " Fix on the host: sudo chown ${QUESTARR_UID}:${QUESTARR_GID} \"${_DB_FILE}\""
exit 1
fi
# Drop root privileges and exec the CMD as questarr
exec su-exec questarr "$@"