@@ -304,25 +304,31 @@ sudo_if() {
304
304
if [ " $( id -u) " -eq 0 ] && [ " $USERNAME " != " root" ]; then
305
305
su - " $USERNAME " -c " $COMMAND "
306
306
else
307
- " $COMMAND "
307
+ $COMMAND
308
308
fi
309
309
}
310
310
311
311
install_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
314
320
}
315
321
316
322
add_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 "
319
325
320
326
# Make sure the config file exists or create it with proper permissions
321
327
test -d " $CONFIG_DIR " || sudo_if mkdir " $CONFIG_DIR "
322
328
test -f " $CONFIG_FILE " || sudo_if touch " $CONFIG_FILE "
323
329
324
330
# 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 "
326
332
}
327
333
328
334
install_python () {
@@ -461,13 +467,26 @@ if [ "${INSTALL_JUPYTERLAB}" = "true" ]; then
461
467
exit 1
462
468
fi
463
469
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
466
477
467
478
# Configure JupyterLab if needed
468
479
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} '"
471
490
fi
472
491
fi
473
492
0 commit comments