From 0329eecec8739d1e175e1d9152b0b233c765ac30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=90=E1=BA=B7ng=20Minh=20D=C5=A9ng?= Date: Sun, 11 Nov 2018 10:24:11 +0700 Subject: [PATCH] fixing inline script problem --- base-notebook/fix-permissions | 2 +- base-notebook/start-notebook.sh | 10 +++---- base-notebook/start-singleuser.sh | 4 +-- base-notebook/start.sh | 46 +++++++++++++++---------------- 4 files changed, 30 insertions(+), 32 deletions(-) diff --git a/base-notebook/fix-permissions b/base-notebook/fix-permissions index c3992d73..659b2763 100755 --- a/base-notebook/fix-permissions +++ b/base-notebook/fix-permissions @@ -17,7 +17,7 @@ set -e -for d in $@; do +for d in "$@"; do find "$d" \ ! \( \ -group $NB_GID \ diff --git a/base-notebook/start-notebook.sh b/base-notebook/start-notebook.sh index d9de07c4..b38c738d 100755 --- a/base-notebook/start-notebook.sh +++ b/base-notebook/start-notebook.sh @@ -6,11 +6,9 @@ set -e if [[ ! -z "${JUPYTERHUB_API_TOKEN}" ]]; then # launched by JupyterHub, use single-user entrypoint - exec /usr/local/bin/start-singleuser.sh $* + exec /usr/local/bin/start-singleuser.sh "$@" +elif [[ ! -z "${JUPYTER_ENABLE_LAB}" ]]; then + . /usr/local/bin/start.sh jupyter lab "$@" else - if [[ ! -z "${JUPYTER_ENABLE_LAB}" ]]; then - . /usr/local/bin/start.sh jupyter lab $* - else - . /usr/local/bin/start.sh jupyter notebook $* - fi + . /usr/local/bin/start.sh jupyter notebook "$@" fi diff --git a/base-notebook/start-singleuser.sh b/base-notebook/start-singleuser.sh index 09c1d695..8cb8caec 100755 --- a/base-notebook/start-singleuser.sh +++ b/base-notebook/start-singleuser.sh @@ -37,7 +37,7 @@ fi if [ ! -z "$JUPYTER_ENABLE_LAB" ]; then NOTEBOOK_BIN="jupyter labhub" else - NOTEBOOK_BIN=jupyterhub-singleuser + NOTEBOOK_BIN="jupyterhub-singleuser" fi -. /usr/local/bin/start.sh $NOTEBOOK_BIN $NOTEBOOK_ARGS $@ +. /usr/local/bin/start.sh $NOTEBOOK_BIN $NOTEBOOK_ARGS "$@" diff --git a/base-notebook/start.sh b/base-notebook/start.sh index 4fd80ae5..ae5af4f6 100755 --- a/base-notebook/start.sh +++ b/base-notebook/start.sh @@ -6,32 +6,32 @@ set -e # Exec the specified command or fall back on bash if [ $# -eq 0 ]; then - cmd=bash + cmd=( "bash" ) else - cmd=$* + cmd=( "$@" ) fi run-hooks () { # Source scripts or run executable files in a directory if [[ ! -d "$1" ]] ; then - return + return fi echo "$0: running hooks in $1" - for f in "$1"/*; do - case "$f" in - *.sh) - echo "$0: running $f" - source "$f" - ;; - *) - if [[ -x "$f" ]] ; then - echo "$0: running $f" - "$f" - else - echo "$0: ignoring $f" - fi - ;; - esac + for f in "$1/"*; do + case "$f" in + *.sh) + echo "$0: running $f" + source "$f" + ;; + *) + if [[ -x "$f" ]] ; then + echo "$0: running $f" + "$f" + else + echo "$0: ignoring $f" + fi + ;; + esac echo "$0: done running hooks in $1" done } @@ -86,7 +86,7 @@ if [ $(id -u) == 0 ] ; then if [ "$NB_GID" != $(id -g $NB_USER) ] ; then echo "Add $NB_USER to group: $NB_GID" groupadd -g $NB_GID -o ${NB_GROUP:-${NB_USER}} - usermod -g $NB_GID -a -G $NB_GID,100 $NB_USER + usermod -g $NB_GID -aG 100 $NB_USER fi # Enable sudo if requested @@ -101,8 +101,8 @@ if [ $(id -u) == 0 ] ; then # Exec the command as NB_USER with the PATH and the rest of # the environment preserved run-hooks /usr/local/bin/before-notebook.d - echo "Executing the command: $cmd" - exec sudo -E -H -u $NB_USER PATH=$PATH XDG_CACHE_HOME=/home/$NB_USER/.cache PYTHONPATH=$PYTHONPATH $cmd + echo "Executing the command: ${cmd[@]}" + exec sudo -E -H -u $NB_USER PATH=$PATH XDG_CACHE_HOME=/home/$NB_USER/.cache PYTHONPATH=$PYTHONPATH "${cmd[@]}" else if [[ "$NB_UID" == "$(id -u jovyan)" && "$NB_GID" == "$(id -g jovyan)" ]]; then # User is not attempting to override user/group via environment @@ -145,6 +145,6 @@ else # Execute the command run-hooks /usr/local/bin/before-notebook.d - echo "Executing the command: $cmd" - exec $cmd + echo "Executing the command: ${cmd[@]}" + exec "${cmd[@]}" fi