forked from ivaano/NsxLibraryManager
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentrypoint.sh
More file actions
53 lines (45 loc) · 1.92 KB
/
entrypoint.sh
File metadata and controls
53 lines (45 loc) · 1.92 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
#!/bin/bash
# This script runs as root initially.
# It reads the target user ID (PUID) and group ID (PGID) from environment variables.
# If PUID/PGID are not set, it defaults to the UID/GID of the 'app' user id (1654) according to base image.
# It changes the ownership of /app/wwwroot to the determined user/group.
# It makes /app/renamer/in writable by owner and group (775).
# Then, it uses gosu to execute the main application command as that user/group.
echo "Starting entrypoint script as root."
# Determine Target UID
if [ -z "${PUID}" ]; then
echo "PUID environment variable not set. Attempting to use 'app' user's UID."
if id -u app > /dev/null 2>&1; then
TARGET_UID=$(id -u app)
echo "Using 'app' user's UID: ${TARGET_UID}"
else
echo "Error: PUID not set and 'app' user does not exist. Cannot determine UID."
exit 1
fi
else
TARGET_UID="${PUID}"
echo "Using PUID environment variable: ${TARGET_UID}"
fi
# Determine Target GID
if [ -z "${PGID}" ]; then
echo "PGID environment variable not set. Attempting to use 'app' user's GID."
if id -g app > /dev/null 2>&1; then
TARGET_GID=$(id -g app)
echo "Using 'app' user's GID: ${TARGET_GID}"
else
echo "Error: PGID not set and 'app' user does not exist. Cannot determine GID."
exit 1
fi
else
TARGET_GID="${PGID}"
echo "Using PGID environment variable: ${TARGET_GID}"
fi
# Change ownership of /app to the target user and group
echo "Changing ownership of /app/wwwroot to ${TARGET_UID}:${TARGET_GID}"
chown -R "${TARGET_UID}":"${TARGET_GID}" /app/wwwroot
# Make only /app/renamer/in writable by owner and group (775)
echo "Setting /app/renamer/in permissions to 775 (owner & group can write)"
chmod 775 /app/renamer/in
# Execute the main application command using gosu to switch to the target user/group
echo "Executing dotnet NsxLibraryManager.dll as user ${TARGET_UID}:${TARGET_GID}"
exec gosu "${TARGET_UID}":"${TARGET_GID}" dotnet NsxLibraryManager.dll