#!/bin/bash # 使用当前用户的家目录环境变量 HOME_PATH="$HOME" MAMBA_ROOT_PREFIX="$HOME/micromamba" JUPYTERHUB_ENV_NAME="jupyterhub_env" MICROMAMBA_INSTALL_SCRIPT="./micromamba/install.sh" CONDARC_PATH="$HOME/.condarc" # 检查 micromamba 是否安装 check_micromamba_installed() { if [[ -f "$MAMBA_ROOT_PREFIX/bin/micromamba" ]]; then echo "micromamba 已安装。" return 0 else echo "micromamba 未安装。" return 1 fi } # 安装 micromamba install_micromamba() { echo "开始安装 micromamba..." bash "$MICROMAMBA_INSTALL_SCRIPT" --silent-install source "$HOME/.bashrc" } # 创建并激活 jupyterhub_env create_and_activate_env() { local env_name=$JUPYTERHUB_ENV_NAME local env_dir="$MAMBA_ROOT_PREFIX/envs" echo "检查 $env_name 环境是否存在..." if [ -d "$env_dir/$env_name" ]; then echo "环境 $env_name 已存在, 跳过。如果需要删除 使用命令: micromamba remove -n $env_name --all --yes 再次执行" else echo "环境 $env_name 不存在,正在创建并激活..." micromamba create -n jupyterhub_env -c conda-forge nodejs jupyterhub jupyterlab notebook jupyter-rsession-proxy ipykernel git jupyterlab-language-pack-zh-CN jupyterlab-git jupyterlab-system-monitor jupyter_nbextensions_configurator jupyter_contrib_nbextensions jupyterlab-unfold jupyterlab-variableinspector jupyterlab_widgets jupyterlab-drawio jupyterlab-spreadsheet-editor jupyterlab-cell-flash jedi-language-server jupyterlab_code_formatter jupyterlab-spellchecker jupyterlab_vim nbresuse ipydrawio jedi ipympl black isort theme-darcula ipywidgets tensorboard jupyterlab_latex jupyter_bokeh autopep8 xeus-python jupyterlab-lsp python-lsp-server nglview mdtraj --yes fi } # 配置 JupyterHub configure_jupyterhub() { echo "配置 JupyterHub..." mkdir -p "$HOME/.jupyterhub" cp "./config/jupyterhub_config.yml" "$HOME/.jupyterhub/jupyterhub_config.yml" } # 配置 .condarc 文件 configure_condarc() { echo "配置 .condarc 文件..." cat < "$CONDARC_PATH" ssl_verify: true channels: - defaults - https://levinthal:paradox@conda.graylab.jhu.edu EOF } # 修改 JupyterHub 配置文件中的端口号 modify_jupyterhub_port() { local config_path="$HOME/.jupyterhub/jupyterhub_config.yml" local new_port=$1 # 使用 sed 来修改配置文件中的端口号 sed -i "s/^c\.JupyterHub\.port = .*/c.JupyterHub.port = $new_port/" "$config_path" echo "JupyterHub 端口已更改为 $new_port。" } # 设置 JupyterHub 服务开机启动 setup_systemd_service() { local service_file="/etc/systemd/system/jupyterhub.service" local user_name=$(whoami) echo "启动权限:$user_name" cat <