-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move responsibility for user and group creation to entrypoint.sh
- Loading branch information
Showing
4 changed files
with
132 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/sh | ||
set -e | ||
|
||
# Default values | ||
PUID=${PUID:-1000} | ||
PGID=${PGID:-1000} | ||
USER_NAME=${USER_NAME:-siyuan} | ||
GROUP_NAME=${GROUP_NAME:-siyuan} | ||
|
||
# Get or create group | ||
group_name=$(getent group "${PGID}" | cut -d: -f1 || echo "${GROUP_NAME}") | ||
if ! getent group "${PGID}" > /dev/null 2>&1; then | ||
echo "Creating group with GID: ${PGID}" | ||
addgroup --gid "${PGID}" "${GROUP_NAME}" | ||
else | ||
echo "Using existing group: ${group_name}" | ||
fi | ||
|
||
# Get or create user | ||
user_name=$(getent passwd "${PUID}" | cut -d: -f1 || echo "${USER_NAME}") | ||
if ! id -u "${PUID}" > /dev/null 2>&1; then | ||
echo "Creating user with UID: ${PUID} and GID: ${PGID}" | ||
adduser --uid "${PUID}" --ingroup "${group_name}" --disabled-password --gecos "" "${user_name}" | ||
else | ||
echo "User with UID ${PUID} already exists, using user: ${user_name}" | ||
fi | ||
|
||
# Change ownership of relevant directories | ||
echo "Adjusting ownership of /opt/siyuan and /home/siyuan/workspace" | ||
chown -R "${PUID}:${PGID}" /opt/siyuan | ||
chown -R "${PUID}:${PGID}" /home/siyuan/workspace | ||
|
||
# Switch to the newly created user and start the main process | ||
echo "Starting Siyuan with UID:${PUID} and GID:${PGID}" | ||
exec su-exec "${PUID}:${PGID}" "$@" |