@@ -172,49 +172,55 @@ if [ "$(id -u)" == 0 ] ; then
172
172
# The container didn't start as the root user, so we will have to act as the
173
173
# user we started as.
174
174
else
175
- # Warn about misconfiguration of: desired username, user id, or group id
176
- if [[ -n " ${NB_USER} " && " ${NB_USER} " != " $( id -un) " ]]; then
177
- _log " WARNING: container must be started as root to change the desired user's name with NB_USER!"
178
- fi
179
- if [[ -n " ${NB_UID} " && " ${NB_UID} " != " $( id -u) " ]]; then
180
- _log " WARNING: container must be started as root to change the desired user's id with NB_UID!"
181
- fi
182
- if [[ -n " ${NB_GID} " && " ${NB_GID} " != " $( id -g) " ]]; then
183
- _log " WARNING: container must be started as root to change the desired user's group id with NB_GID!"
184
- fi
185
-
186
175
# Warn about misconfiguration of: granting sudo rights
187
176
if [[ " ${GRANT_SUDO} " == " 1" || " ${GRANT_SUDO} " == " yes" ]]; then
188
177
_log " WARNING: container must be started as root to grant sudo permissions!"
189
178
fi
190
179
180
+ JOVYAN_UID=" $( id -u jovyan 2> /dev/null) " # The default UID for the jovyan user
181
+ JOVYAN_GID=" $( id -g jovyan 2> /dev/null) " # The default GID for the jovyan user
182
+
191
183
# Attempt to ensure the user uid we currently run as has a named entry in
192
184
# the /etc/passwd file, as it avoids software crashing on hard assumptions
193
185
# on such entry. Writing to the /etc/passwd was allowed for the root group
194
186
# from the Dockerfile during build.
195
187
#
196
188
# ref: https://github.com/jupyter/docker-stacks/issues/552
197
189
if ! whoami & > /dev/null; then
198
- _log " There is no entry in /etc/passwd for our UID. Attempting to fix..."
190
+ _log " There is no entry in /etc/passwd for our UID= $( id -u ) . Attempting to fix..."
199
191
if [[ -w /etc/passwd ]]; then
200
192
_log " Renaming old jovyan user to nayvoj ($( id -u jovyan) :$( id -g jovyan) )"
201
193
202
194
# We cannot use "sed --in-place" since sed tries to create a temp file in
203
195
# /etc/ and we may not have write access. Apply sed on our own temp file:
204
196
sed --expression=" s/^jovyan:/nayvoj:/" /etc/passwd > /tmp/passwd
205
- echo " jovyan :x:$( id -u) :$( id -g) :,,,:/home/jovyan:/bin/bash" >> /tmp/passwd
197
+ echo " ${NB_USER} :x:$( id -u) :$( id -g) :,,,:/home/jovyan:/bin/bash" >> /tmp/passwd
206
198
cat /tmp/passwd > /etc/passwd
207
199
rm /tmp/passwd
208
200
209
- _log " Added new jovyan user ($( id -u) :$( id -g) ). Fixed UID!"
201
+ _log " Added new ${NB_USER} user ($( id -u) :$( id -g) ). Fixed UID!"
210
202
else
211
- _log " WARNING: unable to fix missing /etc/passwd entry because we don't have write permission."
203
+ _log " WARNING: unable to fix missing /etc/passwd entry because we don't have write permission. Try setting gid=0 with \" --user= $( id -u ) :0 \" . "
212
204
fi
213
205
fi
214
206
207
+ # Warn about misconfiguration of: desired username, user id, or group id.
208
+ # A misconfiguration occurs when the user modifies the default values of
209
+ # NB_USER, NB_UID, or NB_GID, but we cannot update those values because we
210
+ # are not root.
211
+ if [[ " ${NB_USER} " != " jovyan" && " ${NB_USER} " != " $( id -un) " ]]; then
212
+ _log " WARNING: container must be started as root to change the desired user's name with NB_USER=\" ${NB_USER} \" !"
213
+ fi
214
+ if [[ " ${NB_UID} " != " ${JOVYAN_UID} " && " ${NB_UID} " != " $( id -u) " ]]; then
215
+ _log " WARNING: container must be started as root to change the desired user's id with NB_UID=\" ${NB_UID} \" !"
216
+ fi
217
+ if [[ " ${NB_GID} " != " ${JOVYAN_GID} " && " ${NB_GID} " != " $( id -g) " ]]; then
218
+ _log " WARNING: container must be started as root to change the desired user's group id with NB_GID=\" ${NB_GID} \" !"
219
+ fi
220
+
215
221
# Warn if the user isn't able to write files to ${HOME}
216
222
if [[ ! -w /home/jovyan ]]; then
217
- _log " WARNING: no write access to /home/jovyan. Try starting the container with group 'users' (100)."
223
+ _log " WARNING: no write access to /home/jovyan. Try starting the container with group 'users' (100), e.g. using \" --group-add=users \" ."
218
224
fi
219
225
220
226
# NOTE: This hook is run as the user we started the container as!
0 commit comments