aboutsummaryrefslogtreecommitdiff
path: root/src/jupyterlab/install.sh
diff options
context:
space:
mode:
authorJosh Spicer <josh@joshspicer.com>2022-05-13 03:07:38 +0300
committerGitHub <noreply@github.com>2022-05-13 03:07:38 +0300
commit1620def8a910d5c3af938708c98a361d0603b5bc (patch)
tree1d930b05987cc024fecf60aeb71c3ffe39ec8e3c /src/jupyterlab/install.sh
parent5332b952adf7e31a744bba297b5232a7000de58a (diff)
parent73e20e52a2d48d915036007ea84db994a01df561 (diff)
Merge branch 'main' of https://github.com/devcontainers/features
Diffstat (limited to 'src/jupyterlab/install.sh')
-rw-r--r--src/jupyterlab/install.sh50
1 files changed, 37 insertions, 13 deletions
diff --git a/src/jupyterlab/install.sh b/src/jupyterlab/install.sh
index 45267b0..f6c93f9 100644
--- a/src/jupyterlab/install.sh
+++ b/src/jupyterlab/install.sh
@@ -1,9 +1,20 @@
#!/usr/bin/env bash
+#-------------------------------------------------------------------------------------------------------------
+# Copyright (c) Microsoft Corporation. All rights reserved.
+# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
+#-------------------------------------------------------------------------------------------------------------
+#
+# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/jupyterlab.md
+# Maintainer: The VS Code and Codespaces Teams
+#
+# Syntax: ./jupyter-debian.sh
set -e
VERSION=${1:-"latest"}
USERNAME=${2:-"automatic"}
+PYTHON=${3:-"python"}
+ALLOW_ORIGIN=${4:-""}
# If in automatic mode, determine if a user already exists, if not use vscode
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
@@ -24,9 +35,8 @@ elif [ "${USERNAME}" = "none" ]; then
USER_GID=0
fi
-# Use sudo to run as non-root user is not already running
-sudoUserIf()
-{
+# Make sure we run the command as non-root user
+sudoUserIf() {
if [ "$(id -u)" -eq 0 ] && [ "${USERNAME}" != "root" ]; then
sudo -u ${USERNAME} "$@"
else
@@ -34,18 +44,32 @@ sudoUserIf()
fi
}
-# If we don't yet have Python, install it now.
-if ! python --version > /dev/null ; then
+addToJupyterConfig() {
+ JUPYTER_DIR="/home/${USERNAME}/.jupyter"
+ JUPYTER_CONFIG="${JUPYTER_DIR}/jupyter_notebook_config.py"
+
+ # Make sure the config file exists
+ test -d ${JUPYTER_DIR} || sudoUserIf mkdir ${JUPYTER_DIR}
+ test -f ${JUPYTER_CONFIG} || sudoUserIf touch ${JUPYTER_CONFIG}
+
+ # Don't write the same line more than once
+ grep -q ${1} ${JUPYTER_CONFIG} || echo ${1} >> ${JUPYTER_CONFIG}
+}
+
+# Make sure that Python is available
+if ! ${PYTHON} --version > /dev/null ; then
echo "You need to install Python before installing JupyterLab."
exit 1
fi
-# If we don't already have JupyterLab installed, install it now.
-if ! jupyter-lab --version > /dev/null ; then
- echo "Installing JupyterLab..."
- if [ "${VERSION}" = "latest" ]; then
- pip install jupyterlab
- else
- pip install jupyterlab=="${VERSION}" --no-cache-dir
- fi
+# pip skips installation if JupyterLab is already installed
+echo "Installing JupyterLab..."
+if [ "${VERSION}" = "latest" ]; then
+ sudoUserIf ${PYTHON} -m pip install jupyterlab --no-cache-dir
+else
+ sudoUserIf ${PYTHON} -m pip install jupyterlab=="${VERSION}" --no-cache-dir
+fi
+
+if [ "${ALLOW_ORIGIN}" = 'true' ]; then
+ addToJupyterConfig "c.ServerApp.allow_origin = '*'"
fi