|
| 1 | +#!/usr/bin/env bash |
| 2 | +#------------------------------------------------------------------------------------------------------------- |
| 3 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 4 | +# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information. |
| 5 | +#------------------------------------------------------------------------------------------------------------- |
| 6 | +# |
| 7 | +# Docs: https://github.com/microsoft/vscode-dev-containers/blob/main/script-library/docs/jupyterlab.md |
| 8 | +# Maintainer: The VS Code and Codespaces Teams |
| 9 | +# |
| 10 | +# Syntax: ./jupyter-debian.sh |
| 11 | + |
| 12 | +set -e |
| 13 | + |
| 14 | +VERSION=${1:-"latest"} |
| 15 | +USERNAME=${2:-"automatic"} |
| 16 | + |
| 17 | +# If in automatic mode, determine if a user already exists, if not use vscode |
| 18 | +if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then |
| 19 | + USERNAME="" |
| 20 | + POSSIBLE_USERS=("vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)") |
| 21 | + for CURRENT_USER in ${POSSIBLE_USERS[@]}; do |
| 22 | + if id -u ${CURRENT_USER} > /dev/null 2>&1; then |
| 23 | + USERNAME=${CURRENT_USER} |
| 24 | + break |
| 25 | + fi |
| 26 | + done |
| 27 | + if [ "${USERNAME}" = "" ]; then |
| 28 | + USERNAME=vscode |
| 29 | + fi |
| 30 | +elif [ "${USERNAME}" = "none" ]; then |
| 31 | + USERNAME=root |
| 32 | + USER_UID=0 |
| 33 | + USER_GID=0 |
| 34 | +fi |
| 35 | + |
| 36 | +# Use sudo to run as non-root user is not already running |
| 37 | +sudoUserIf() |
| 38 | +{ |
| 39 | + if [ "$(id -u)" -eq 0 ] && [ "${USERNAME}" != "root" ]; then |
| 40 | + sudo -u ${USERNAME} "$@" |
| 41 | + else |
| 42 | + "$@" |
| 43 | + fi |
| 44 | +} |
| 45 | + |
| 46 | +# If we don't yet have Python, install it now. |
| 47 | +if ! python --version > /dev/null ; then |
| 48 | + echo "You need to install Python before installing JupyterLab." |
| 49 | + exit 1 |
| 50 | +fi |
| 51 | + |
| 52 | +# If we don't already have JupyterLab installed, install it now. |
| 53 | +if ! jupyter-lab --version > /dev/null ; then |
| 54 | + echo "Installing JupyterLab..." |
| 55 | + if [ "${VERSION}" = "latest" ]; then |
| 56 | + sudoUserIf pip install jupyterlab |
| 57 | + else |
| 58 | + sudoUserIf pip install jupyterlab=="${VERSION}" --no-cache-dir |
| 59 | + fi |
| 60 | +fi |
0 commit comments