Commit c1380704 authored by Peter Parente's avatar Peter Parente

Fix working directory problems with custom NB_USER

Improve start.sh logging along the way
parent 16e6d72c
......@@ -6,18 +6,23 @@ set -e
# Handle special flags if we're root
if [ $(id -u) == 0 ] ; then
# Switch to the root of the container in case we start adjusting paths
# that impact the default working directory
cd /
# Handle username change. Since this is cheap, do this unconditionally
usermod -d /home/$NB_USER -l $NB_USER jovyan
echo "Set username to: $NB_USER"
usermod -m -d /home/$NB_USER -l $NB_USER jovyan
# Change UID of NB_USER to NB_UID if it does not match
if [ "$NB_UID" != $(id -u $NB_USER) ] ; then
echo "Set user UID to: $NB_UID"
echo "Set $NB_USER UID to: $NB_UID"
usermod -u $NB_UID $NB_USER
fi
# Change GID of NB_USER to NB_GID if NB_GID is passed as a parameter
if [ "$NB_GID" ] ; then
echo "Change GID to $NB_GID"
echo "Set $NB_USER GID to: $NB_GID"
groupmod -g $NB_GID -o $(id -g -n $NB_USER)
fi
......@@ -27,8 +32,11 @@ if [ $(id -u) == 0 ] ; then
echo "$NB_USER ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/notebook
fi
# Switch to the user's home directory after adjusting any paths
cd /home/$NB_USER
# Exec the command as NB_USER
echo "Execute the command as $NB_USER"
echo "Execute the command: $*"
exec su $NB_USER -c "env PATH=$PATH $*"
else
if [[ ! -z "$NB_UID" && "$NB_UID" != "$(id -u)" ]]; then
......@@ -41,6 +49,6 @@ else
echo 'Container must be run as root to grant sudo permissions'
fi
# Exec the command
echo "Execute the command"
echo "Execute the command: $*"
exec $*
fi
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment