@@ -21,6 +21,7 @@ run-hooks () {
2121 case " $f " in
2222 * .sh)
2323 echo " $0 : running $f "
24+ # shellcheck disable=SC1090
2425 source " $f "
2526 ;;
2627 * )
@@ -39,12 +40,12 @@ run-hooks () {
3940run-hooks /usr/local/bin/start-notebook.d
4041
4142# Handle special flags if we're root
42- if [ $( id -u) == 0 ] ; then
43+ if [ " $( id -u) " == 0 ] ; then
4344
4445 # Only attempt to change the jovyan username if it exists
4546 if id jovyan & > /dev/null ; then
4647 echo " Set username to: $NB_USER "
47- usermod -d /home/$NB_USER -l $NB_USER jovyan
48+ usermod -d " /home/$NB_USER " -l " $NB_USER " jovyan
4849 fi
4950
5051 # handle home and working directory if the username changed
@@ -67,23 +68,25 @@ if [ $(id -u) == 0 ] ; then
6768 # Ex: default NFS/EFS (no auto-uid/gid)
6869 if [[ " $CHOWN_HOME " == " 1" || " $CHOWN_HOME " == ' yes' ]]; then
6970 echo " Changing ownership of /home/$NB_USER to $NB_UID :$NB_GID with options '${CHOWN_HOME_OPTS} '"
70- chown $CHOWN_HOME_OPTS $NB_UID :$NB_GID /home/$NB_USER
71+ # shellcheck disable=SC2086
72+ chown $CHOWN_HOME_OPTS " $NB_UID :$NB_GID " " /home/$NB_USER "
7173 fi
72- if [ ! -z " $CHOWN_EXTRA " ]; then
73- for extra_dir in $( echo $CHOWN_EXTRA | tr ' ,' ' ' ) ; do
74+ if [ -n " $CHOWN_EXTRA " ]; then
75+ for extra_dir in $( echo " $CHOWN_EXTRA " | tr ' ,' ' ' ) ; do
7476 echo " Changing ownership of ${extra_dir} to $NB_UID :$NB_GID with options '${CHOWN_EXTRA_OPTS} '"
75- chown $CHOWN_EXTRA_OPTS $NB_UID :$NB_GID $extra_dir
77+ # shellcheck disable=SC2086
78+ chown $CHOWN_EXTRA_OPTS " $NB_UID :$NB_GID " " $extra_dir "
7679 done
7780 fi
7881
7982 # Change UID:GID of NB_USER to NB_UID:NB_GID if it does not match
80- if [ " $NB_UID " != $( id -u $NB_USER ) ] || [ " $NB_GID " != $( id -g $NB_USER ) ]; then
83+ if [ " $NB_UID " != " $( id -u " $NB_USER " ) " ] || [ " $NB_GID " != " $( id -g " $NB_USER " ) " ]; then
8184 echo " Set user $NB_USER UID:GID to: $NB_UID :$NB_GID "
82- if [ " $NB_GID " != $( id -g $NB_USER ) ]; then
83- groupadd -f -g $NB_GID -o ${NB_GROUP:- ${NB_USER} }
85+ if [ " $NB_GID " != " $( id -g " $NB_USER " ) " ]; then
86+ groupadd -f -g " $NB_GID " -o " ${NB_GROUP:- ${NB_USER} } "
8487 fi
85- userdel $NB_USER
86- useradd --home /home/$NB_USER -u $NB_UID -g $NB_GID -G 100 -l $NB_USER
88+ userdel " $NB_USER "
89+ useradd --home " /home/$NB_USER " -u " $NB_UID " -g " $NB_GID " -G 100 -l " $NB_USER "
8790 fi
8891
8992 # Enable sudo if requested
@@ -98,8 +101,8 @@ if [ $(id -u) == 0 ] ; then
98101 # Exec the command as NB_USER with the PATH and the rest of
99102 # the environment preserved
100103 run-hooks /usr/local/bin/before-notebook.d
101- echo " Executing the command: ${cmd[@]} "
102- exec sudo -E -H -u $NB_USER PATH=$PATH XDG_CACHE_HOME=/home/$NB_USER /.cache PYTHONPATH=${PYTHONPATH:- } " ${cmd[@]} "
104+ echo " Executing the command:" " ${cmd[@]} "
105+ exec sudo -E -H -u " $NB_USER " PATH=" $PATH " XDG_CACHE_HOME=" /home/$NB_USER /.cache" PYTHONPATH=" ${PYTHONPATH:- } " " ${cmd[@]} "
103106else
104107 if [[ " $NB_UID " == " $( id -u jovyan 2> /dev/null) " && " $NB_GID " == " $( id -g jovyan 2> /dev/null) " ]]; then
105108 # User is not attempting to override user/group via environment
110113 if [[ " $STATUS " != " 0" ]]; then
111114 if [[ -w /etc/passwd ]]; then
112115 echo " Adding passwd file entry for $( id -u) "
113- cat /etc/passwd | sed -e " s/^jovyan:/nayvoj:/" > /tmp/passwd
116+ sed -e " s/^jovyan:/nayvoj:/" /etc/passwd > /tmp/passwd
114117 echo " jovyan:x:$( id -u) :$( id -g) :,,,:/home/jovyan:/bin/bash" >> /tmp/passwd
115118 cat /tmp/passwd > /etc/passwd
116119 rm /tmp/passwd
@@ -126,11 +129,11 @@ else
126129 else
127130 # Warn if looks like user want to override uid/gid but hasn't
128131 # run the container as root.
129- if [[ ! -z " $NB_UID " && " $NB_UID " != " $( id -u) " ]]; then
130- echo ' Container must be run as root to set $NB_UID'
132+ if [[ -n " $NB_UID " && " $NB_UID " != " $( id -u) " ]]; then
133+ echo " Container must be run as root to set NB_UID to $NB_UID "
131134 fi
132- if [[ ! -z " $NB_GID " && " $NB_GID " != " $( id -g) " ]]; then
133- echo ' Container must be run as root to set $NB_GID'
135+ if [[ -n " $NB_GID " && " $NB_GID " != " $( id -g) " ]]; then
136+ echo " Container must be run as root to set NB_GID to $NB_GID "
134137 fi
135138 fi
136139
142145
143146 # Execute the command
144147 run-hooks /usr/local/bin/before-notebook.d
145- echo " Executing the command: ${cmd[@]} "
148+ echo " Executing the command:" " ${cmd[@]} "
146149 exec " ${cmd[@]} "
147150fi
0 commit comments