@@ -304,25 +304,31 @@ sudo_if() {
304304 if [ " $( id -u) " -eq 0 ] && [ " $USERNAME " != " root" ]; then
305305 su - " $USERNAME " -c " $COMMAND "
306306 else
307- " $COMMAND "
307+ $COMMAND
308308 fi
309309}
310310
311311install_user_package () {
312- PACKAGE=" $1 "
313- sudo_if " ${PYTHON_SRC} " -m pip install --user --upgrade --no-cache-dir " $PACKAGE "
312+ INSTALL_UNDER_ROOT=" $1 "
313+ PACKAGE=" $2 "
314+
315+ if [ " $INSTALL_UNDER_ROOT " = true ]; then
316+ sudo_if " ${PYTHON_SRC} " -m pip install --upgrade --no-cache-dir " $PACKAGE "
317+ else
318+ sudo_if " ${PYTHON_SRC} " -m pip install --user --upgrade --no-cache-dir " $PACKAGE "
319+ fi
314320}
315321
316322add_user_jupyter_config () {
317- CONFIG_DIR=" /home/ $USERNAME /.jupyter "
318- CONFIG_FILE=" $CONFIG_DIR /jupyter_server_config.py "
323+ CONFIG_DIR=" $1 "
324+ CONFIG_FILE=" $2 "
319325
320326 # Make sure the config file exists or create it with proper permissions
321327 test -d " $CONFIG_DIR " || sudo_if mkdir " $CONFIG_DIR "
322328 test -f " $CONFIG_FILE " || sudo_if touch " $CONFIG_FILE "
323329
324330 # Don't write the same config more than once
325- grep -q " $1 " " $CONFIG_FILE " || echo " $1 " >> " $CONFIG_FILE "
331+ grep -q " $3 " " $CONFIG_FILE " || echo " $3 " >> " $CONFIG_FILE "
326332}
327333
328334install_python () {
@@ -461,13 +467,26 @@ if [ "${INSTALL_JUPYTERLAB}" = "true" ]; then
461467 exit 1
462468 fi
463469
464- install_user_package jupyterlab
465- install_user_package jupyterlab-git
470+ INSTALL_UNDER_ROOT=true
471+ if [ " $( id -u) " -eq 0 ] && [ " $USERNAME " != " root" ]; then
472+ INSTALL_UNDER_ROOT=false
473+ fi
474+
475+ install_user_package $INSTALL_UNDER_ROOT jupyterlab
476+ install_user_package $INSTALL_UNDER_ROOT jupyterlab-git
466477
467478 # Configure JupyterLab if needed
468479 if [ -n " ${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN} " ]; then
469- add_user_jupyter_config " c.ServerApp.allow_origin = '${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN} '"
470- add_user_jupyter_config " c.NotebookApp.allow_origin = '${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN} '"
480+ # Resolve config directory
481+ CONFIG_DIR=" /root/.jupyter"
482+ if [ " $INSTALL_UNDER_ROOT " = false ]; then
483+ CONFIG_DIR=" /home/$USERNAME /.jupyter"
484+ fi
485+
486+ CONFIG_FILE=" $CONFIG_DIR /jupyter_server_config.py"
487+
488+ add_user_jupyter_config $CONFIG_DIR $CONFIG_FILE " c.ServerApp.allow_origin = '${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN} '"
489+ add_user_jupyter_config $CONFIG_DIR $CONFIG_FILE " c.NotebookApp.allow_origin = '${CONFIGURE_JUPYTERLAB_ALLOW_ORIGIN} '"
471490 fi
472491fi
473492
0 commit comments