1: 2021-07-03 (土) 18:58:49 iseki |
現: 2021-07-13 (火) 20:06:59 iseki |
- | #!/bin/bash | + | **** /usr/local/bin/start.sh [#g40ccb19] |
| + | #!/bin/bash |
| # Copyright (c) Jupyter Development Team. | | # Copyright (c) Jupyter Development Team. |
| # Distributed under the terms of the Modified BSD License. | | # Distributed under the terms of the Modified BSD License. |
| + | |
| set -e | | set -e |
| + | |
| # Exec the specified command or fall back on bash | | # Exec the specified command or fall back on bash |
| if [ $# -eq 0 ]; then | | if [ $# -eq 0 ]; then |
| cmd=( "$@" ) | | cmd=( "$@" ) |
| fi | | fi |
| + | |
| run-hooks () { | | run-hooks () { |
| # Source scripts or run executable files in a directory | | # Source scripts or run executable files in a directory |
| echo "$0: done running hooks in $1" | | echo "$0: done running hooks in $1" |
| } | | } |
| + | |
| run-hooks /usr/local/bin/start-notebook.d | | run-hooks /usr/local/bin/start-notebook.d |
| + | |
| # Handle special flags if we're root | | # Handle special flags if we're root |
| if [ $(id -u) == 0 ] ; then | | if [ $(id -u) == 0 ] ; then |
| + | |
| # Only attempt to change the jovyan username if it exists | | # Only attempt to change the jovyan username if it exists |
| if id jovyan &> /dev/null ; then | | if id jovyan &> /dev/null ; then |
| usermod -d /home/$NB_USER -l $NB_USER jovyan | | usermod -d /home/$NB_USER -l $NB_USER jovyan |
| fi | | fi |
| + | |
| # Handle case where provisioned storage does not have the correct permissions by default | | # Handle case where provisioned storage does not have the correct permissions by default |
| # Ex: default NFS/EFS (no auto-uid/gid) | | # Ex: default NFS/EFS (no auto-uid/gid) |
| done | | done |
| fi | | fi |
| + | |
| # handle home and working directory if the username changed | | # handle home and working directory if the username changed |
| if [[ "$NB_USER" != "jovyan" ]]; then | | if [[ "$NB_USER" != "jovyan" ]]; then |
| fi | | fi |
| fi | | fi |
| + | |
| # Change UID:GID of NB_USER to NB_UID:NB_GID if it does not match | | # Change UID:GID of NB_USER to NB_UID:NB_GID if it does not match |
| if [ "$NB_UID" != $(id -u $NB_USER) ] || [ "$NB_GID" != $(id -g $NB_USER) ]; then | | if [ "$NB_UID" != $(id -u $NB_USER) ] || [ "$NB_GID" != $(id -g $NB_USER) ]; then |
| useradd --home /home/$NB_USER -u $NB_UID -g $NB_GID -G 100 -l $NB_USER | | useradd --home /home/$NB_USER -u $NB_UID -g $NB_GID -G 100 -l $NB_USER |
| fi | | fi |
| + | |
| # Enable sudo if requested | | # Enable sudo if requested |
| if [[ "$GRANT_SUDO" == "1" || "$GRANT_SUDO" == 'yes' ]]; then | | if [[ "$GRANT_SUDO" == "1" || "$GRANT_SUDO" == 'yes' ]]; then |
| echo "$NB_USER ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/notebook | | echo "$NB_USER ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/notebook |
| fi | | fi |
| + | |
| # Add $CONDA_DIR/bin to sudo secure_path | | # Add $CONDA_DIR/bin to sudo secure_path |
| sed -r "s#Defaults\s+secure_path\s*=\s*\"?([^\"]+)\"?#Defaults secure_path=\"\1:$CONDA_DIR/bin\"#" /etc/sudoers | grep secure_path > /etc/sudoers.d/path | | sed -r "s#Defaults\s+secure_path\s*=\s*\"?([^\"]+)\"?#Defaults secure_path=\"\1:$CONDA_DIR/bin\"#" /etc/sudoers | grep secure_path > /etc/sudoers.d/path |
| + | |
| # Exec the command as NB_USER with the PATH and the rest of | | # Exec the command as NB_USER with the PATH and the rest of |
| # the environment preserved | | # the environment preserved |
| fi | | fi |
| fi | | fi |
| + | |
| # Warn if the user isn't going to be able to write files to $HOME. | | # Warn if the user isn't going to be able to write files to $HOME. |
| if [[ ! -w /home/jovyan ]]; then | | if [[ ! -w /home/jovyan ]]; then |
| fi | | fi |
| fi | | fi |
| + | |
| # Warn if looks like user want to run in sudo mode but hasn't run | | # Warn if looks like user want to run in sudo mode but hasn't run |
| # the container as root. | | # the container as root. |
| echo 'Container must be run as root to grant sudo permissions' | | echo 'Container must be run as root to grant sudo permissions' |
| fi | | fi |
| + | |
| # Execute the command | | # Execute the command |
| run-hooks /usr/local/bin/before-notebook.d | | run-hooks /usr/local/bin/before-notebook.d |