forked from carlreid/StreamMaster
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
44 lines (39 loc) · 1.28 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
#!/bin/bash
user_name="nonRootUser"
group_name="nonRootGroup"
# Check if PUID or PGID is set to a non-root value
if [ "$PUID" -ne 0 ]; then
if getent passwd $PUID > /dev/null 2>&1; then
user_name=$(getent passwd $PUID | cut -d: -f1)
else
adduser --uid $PUID --disabled-password --gecos "nonRootUser" --force-badname "nonRootUser"
fi
fi
if [ "$PGID" -ne 0 ]; then
if getent group $PGID > /dev/null 2>&1; then
group_name=$(getent group $PGID | cut -d: -f1)
else
addgroup --gid $PGID --force-badname "nonRootGroup"
fi
fi
# Change ownership of the /app directory
if [ "$PUID" -ne 0 ] || [ "$PGID" -ne 0 ]; then
echo "Changing ownership of /app to ${PUID:-0}:${PGID:-0}"
chown -R ${PUID:-0}:${PGID:-0} /app
echo "Changing ownership of /config to ${PUID:-0}:${PGID:-0}"
chown -R ${PUID:-0}:${PGID:-0} /config
fi
# Execute the main application as the specified user
if [ "$PUID" -ne 0 ] && [ "$PGID" -ne 0 ]; then
echo "Running as $user_name:$group_name"
exec gosu $user_name:$group_name "$@"
elif [ "$PUID" -ne 0 ]; then
echo "Running as $user_name"
exec gosu $user_name "$@"
elif [ "$PGID" -ne 0 ]; then
echo "Running as :$group_name"
exec gosu :$group_name "$@"
else
echo "Running as root"
exec "$@"
fi