diff --git a/README.md b/README.md index f50626f..78eb626 100644 --- a/README.md +++ b/README.md @@ -54,4 +54,6 @@ UID: the uid of the user GID: the gid of the user RUN_USER: the username of the user RUN_GROUP: the group of the user +OTHER_GID: list of supplementary gid (comma separated) which the user is also a member of +OTHER_RUN_GROUP: list of supplementary group (comma separated) which the user is also a member of. The order must match the order used for OTHER_GID. ``` diff --git a/scripts/pre-launch.d/08script_user b/scripts/pre-launch.d/08script_user index c95d49f..c390707 100755 --- a/scripts/pre-launch.d/08script_user +++ b/scripts/pre-launch.d/08script_user @@ -3,7 +3,19 @@ if [ -n "$GID" ]; then getent group $RUN_GROUP &> /dev/null || groupadd $GIDoption $RUN_GROUP fi +if [ -n "$OTHER_GID" ]; then + IFS=',' read -ra OTHER_GID_ARRAY <<< "$OTHER_GID" + IFS=',' read -ra OTHER_RUN_GROUP_ARRAY <<< "$OTHER_RUN_GROUP" + length=${#OTHER_GID_ARRAY[@]} + groups="--groups " + for (( i=0; i<$length; i++ )); do + getent group ${OTHER_RUN_GROUP_ARRAY[i]} &> /dev/null || groupadd --gid ${OTHER_GID_ARRAY[i]} ${OTHER_RUN_GROUP_ARRAY[i]} + groups+="${OTHER_GID_ARRAY[i]}," + done + otherGIDoption=${groups::-1} +fi + if [ -n "$UID" ]; then UIDoption="--uid $UID" - id -u $RUN_USER &> /dev/null || useradd -d /tmp/$RUN_USER --create-home --no-user-group $UIDoption $GIDoption $RUN_USER + id -u $RUN_USER &> /dev/null || useradd -d /tmp/$RUN_USER --create-home --no-user-group $UIDoption $GIDoption $otherGIDoption $RUN_USER fi