mirror of
https://github.com/rustmailer/bichon.git
synced 2026-08-03 07:48:34 +02:00
fix: PUID is taken in default ubuntu base image #132
This commit is contained in:
+15
-10
@@ -16,29 +16,34 @@ fi
|
|||||||
switch_user() {
|
switch_user() {
|
||||||
local puid="$1"
|
local puid="$1"
|
||||||
local pgid="$2"
|
local pgid="$2"
|
||||||
|
local USER_NAME
|
||||||
|
local GROUP_NAME
|
||||||
|
|
||||||
# group: avoid GID conflict
|
# group
|
||||||
if ! getent group "$pgid" >/dev/null 2>&1; then
|
if getent group "$pgid" >/dev/null 2>&1; then
|
||||||
|
GROUP_NAME=$(getent group "$pgid" | cut -d: -f1)
|
||||||
|
else
|
||||||
groupadd -g "$pgid" bichon
|
groupadd -g "$pgid" bichon
|
||||||
|
GROUP_NAME=bichon
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# user: ensure bichon exists
|
# user
|
||||||
if ! getent passwd bichon >/dev/null 2>&1; then
|
if getent passwd "$puid" >/dev/null 2>&1; then
|
||||||
useradd -u "$puid" -g "$pgid" -s /bin/bash -d /data bichon
|
USER_NAME=$(getent passwd "$puid" | cut -d: -f1)
|
||||||
|
else
|
||||||
|
useradd -u "$puid" -g "$GROUP_NAME" -s /bin/bash -d /data bichon
|
||||||
|
USER_NAME=bichon
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Change ownership of directories that the process needs to write to
|
|
||||||
chown -R "$puid:$pgid" /data
|
chown -R "$puid:$pgid" /data
|
||||||
chown -R "$puid:$pgid" /opt/bichon
|
chown -R "$puid:$pgid" /opt/bichon
|
||||||
# Handle mounted storage directories if they exist
|
|
||||||
[ -d /envelope ] && chown -R "$puid:$pgid" /envelope
|
[ -d /envelope ] && chown -R "$puid:$pgid" /envelope
|
||||||
[ -d /eml ] && chown -R "$puid:$pgid" /eml
|
[ -d /eml ] && chown -R "$puid:$pgid" /eml
|
||||||
|
|
||||||
# Switch to the user and execute the command
|
exec runuser -u "$USER_NAME" -- "$@"
|
||||||
exec runuser -u bichon -- "$@"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# Check if PUID and PGID are set
|
# Check if PUID and PGID are set
|
||||||
if [ -n "$PUID" ] && [ -n "$PGID" ]; then
|
if [ -n "$PUID" ] && [ -n "$PGID" ]; then
|
||||||
echo "Switching to user with PUID=$PUID, PGID=$PGID"
|
echo "Switching to user with PUID=$PUID, PGID=$PGID"
|
||||||
|
|||||||
Reference in New Issue
Block a user