Commit c560907e authored by Peter Parente's avatar Peter Parente

Fix missing env vars (inc. PATH) in some cases

* Refactor to use sudo to become jovyna when the
  container starts as root
* Retain all environment variables when becoming
  jovyan
* Handle start.sh without additional commands when
  launching a container as NB_USER too
parent b928811d
...@@ -4,6 +4,13 @@ ...@@ -4,6 +4,13 @@
set -e set -e
# Exec the specified command or fall back on bash
if [ $# -eq 0 ]; then
cmd=bash
else
cmd=$*
fi
# Handle special flags if we're root # Handle special flags if we're root
if [ $(id -u) == 0 ] ; then if [ $(id -u) == 0 ] ; then
...@@ -45,34 +52,22 @@ if [ $(id -u) == 0 ] ; then ...@@ -45,34 +52,22 @@ if [ $(id -u) == 0 ] ; then
echo "$NB_USER ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/notebook echo "$NB_USER ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/notebook
fi fi
# Exec the command as NB_USER or root # Exec the command as NB_USER with the PATH and the rest of
echo "Execute the command: $*" # the environment preserved
echo "Executing the command: $cmd"
exec sudo -E -H -u $NB_USER PATH=$PATH $cmd
else
if [[ ! -z "$NB_UID" && "$NB_UID" != "$(id -u)" ]]; then
echo 'Container must be run as root to set $NB_UID'
fi
if [[ ! -z "$NB_GID" && "$NB_GID" != "$(id -g)" ]]; then
echo 'Container must be run as root to set $NB_GID'
fi
if [[ "$GRANT_SUDO" == "1" || "$GRANT_SUDO" == 'yes' ]]; then if [[ "$GRANT_SUDO" == "1" || "$GRANT_SUDO" == 'yes' ]]; then
if [ $# -eq 0 ]; then echo 'Container must be run as root to grant sudo permissions'
echo "No arguments supplied"
sudo -H -u $NB_USER bash -c 'env; PATH=$PATH; bash'
else
exec su $NB_USER -c "env PATH=$PATH $*"
fi
else
if [ $# -eq 0 ]; then
echo "No arguments supplied"
bash -c 'env; PATH=$PATH; bash'
else
env PATH=$PATH $*
fi
fi fi
else
if [[ ! -z "$NB_UID" && "$NB_UID" != "$(id -u)" ]]; then # Execute the command
echo 'Container must be run as root to set $NB_UID' echo "Executing the command: $cmd"
fi exec $cmd
if [[ ! -z "$NB_GID" && "$NB_GID" != "$(id -g)" ]]; then
echo 'Container must be run as root to set $NB_GID'
fi
if [[ "$GRANT_SUDO" == "1" || "$GRANT_SUDO" == 'yes' ]]; then
echo 'Container must be run as root to grant sudo permissions'
fi
# Exec the command
echo "Execute the command: $*"
exec $*
fi 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