@@ -18,7 +18,6 @@ if [ -z "${EDK2_DOCKER_USER_HOME}" ] || [ ! -d "${EDK2_DOCKER_USER_HOME}" ]; the
1818 exit 1
1919fi
2020
21-
2221# ####################################################################
2322# Create a user to run the command
2423#
3130# - If the caller provides a username, we'll use it. Otherwise, just use an
3231# arbitrary username.
3332EDK2_DOCKER_USER=${EDK2_DOCKER_USER:- edk2}
34- #
35- # - Get the uid and gid from the user's home directory.
36- user_uid=$( stat -c " %u" " ${EDK2_DOCKER_USER_HOME} " )
37- user_gid=$( stat -c " %g" " ${EDK2_DOCKER_USER_HOME} " )
38- #
39- # - Add the group. We'll take a shortcut here and always name it the same as
40- # the username. The name is cosmetic, though. The important thing is that the
41- # gid matches.
42- groupadd " ${EDK2_DOCKER_USER} " -f -o -g " ${user_gid} "
43- #
44- # - Add the user.
45- useradd " ${EDK2_DOCKER_USER} " -o -u " ${user_uid} " -g " ${user_gid} " \
46- -G sudo -d " ${EDK2_DOCKER_USER_HOME} " -M -s /bin/bash
4733
48- echo " ${EDK2_DOCKER_USER} " :tianocore | chpasswd
34+ # Create group and user only when {EDK2_DOCKER_USER} not exists
35+ if ! id -u " ${EDK2_DOCKER_USER} " > /dev/null 2>&1 ; then
4936
50- # ####################################################################
51- # Cleanup variables
52- unset user_uid
53- unset user_gid
37+ # - Get the uid and gid from the user's home directory.
38+ user_uid=$( stat -c " %u" " ${EDK2_DOCKER_USER_HOME} " )
39+ user_gid=$( stat -c " %g" " ${EDK2_DOCKER_USER_HOME} " )
5440
41+ # - Add the group. We'll take a shortcut here and always name it the same as
42+ # the username. The name is cosmetic, though. The important thing is that the
43+ # gid matches.
44+ groupadd " ${EDK2_DOCKER_USER} " -f -o -g " ${user_gid} "
45+
46+ # - Add the user.
47+ useradd " ${EDK2_DOCKER_USER} " -o -u " ${user_uid} " -g " ${user_gid} " \
48+ -G sudo -d " ${EDK2_DOCKER_USER_HOME} " -M -s /bin/bash
49+ echo " ${EDK2_DOCKER_USER} " :tianocore | chpasswd
50+
51+ # Cleanup variables
52+ unset user_uid
53+ unset user_gid
54+
55+ fi
5556
5657# ####################################################################
5758# Drop permissions and run the command
0 commit comments