|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | +set -vx |
| 5 | + |
| 6 | +conda_prefix=$HOME/.conda |
| 7 | +jupyterlab_env="base" |
| 8 | +kernel_env="python-3.9" |
| 9 | + |
| 10 | +# Fix the owner and permissions for /home/jovyan |
| 11 | +# TODO: check if passwordless sudo is enabled |
| 12 | +sudo chown jovyan:jovyan /home/jovyan |
| 13 | +sudo chmod 00700 /home/jovyan |
| 14 | + |
| 15 | +cd ~ |
| 16 | + |
| 17 | +rm -rf $conda_prefix #FIXME |
| 18 | + |
| 19 | +if [[ ! -d $conda_prefix ]]; then |
| 20 | + echo "$conda_prefix does not exists, copying from /template" |
| 21 | + tar x -Ipixz -f /template/conda.tar.xz |
| 22 | +fi |
| 23 | + |
| 24 | +if [[ ! -f ~/.profile ]]; then |
| 25 | + echo "No .profile in $HOME, creating one" |
| 26 | + echo "source $conda_prefix/etc/profile.d/conda.sh" >> ~/.profile |
| 27 | + echo "conda activate python-3.9" >> ~/.profile |
| 28 | +fi |
| 29 | + |
| 30 | +if [[ ! -f ~/.jupyter/jupyter_config.json ]]; then |
| 31 | + echo "no .jupyter/jupyter_config.json in $HOME, creating one" |
| 32 | + mkdir -p ~/.jupyter |
| 33 | + # Use kernel display_name, filter out a kernel from jupyterlab environment |
| 34 | + cat <<EOF > ~/.jupyter/jupyter_config.json |
| 35 | +{ |
| 36 | + "CondaKernelSpecManager": { |
| 37 | + "conda_only": true, |
| 38 | + "name_format": "{display_name}" |
| 39 | + } |
| 40 | +} |
| 41 | +EOF |
| 42 | + |
| 43 | + # Use environment name for display_name |
| 44 | + kernel_json=$conda_prefix/envs/$kernel_env/share/jupyter/kernels/python3/kernel.json |
| 45 | + jq ".display_name = \"$kernel_env\"" $kernel_json > /tmp/kernel.json |
| 46 | + mv /tmp/kernel.json $kernel_json |
| 47 | + unset kernel_json |
| 48 | +fi |
| 49 | + |
| 50 | +source $conda_prefix/etc/profile.d/conda.sh |
| 51 | +conda activate $jupyterlab_env |
| 52 | + |
| 53 | +unset conda_prefix |
| 54 | +unset jupyterlab_env |
| 55 | +unset kernel_env |
| 56 | + |
| 57 | +# Remove default kernel |
| 58 | +jupyter kernelspec remove -y python3 || true |
| 59 | + |
| 60 | +# Remove lost+found |
| 61 | +rm -rf lost+found |
| 62 | + |
| 63 | +find ~/.conda -name '*singleuser' |
| 64 | + |
| 65 | +exec jupyterhub-singleuser |
0 commit comments