Skip to content

Commit a59a9e6

Browse files
authored
Merge pull request #1315 from mathbunnyru/asalikhov/shellcheck
Fix shellcheck warnings
2 parents 3e78827 + f961906 commit a59a9e6

File tree

14 files changed

+70
-55
lines changed

14 files changed

+70
-55
lines changed

.pre-commit-config.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ repos:
2323
hooks:
2424
- id: bashate
2525
args: ["--ignore=E006"]
26+
- repo: https://github.com/shellcheck-py/shellcheck-py
27+
rev: v0.7.2.1
28+
hooks:
29+
- id: shellcheck
30+
args: ["-x"]
2631
- repo: https://gitlab.com/pycqa/flake8
2732
rev: 3.9.1
2833
hooks:

base-notebook/fix-permissions

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ set -e
2020
for d in "$@"; do
2121
find "$d" \
2222
! \( \
23-
-group $NB_GID \
23+
-group "${NB_GID}" \
2424
-a -perm -g+rwX \
2525
\) \
26-
-exec chgrp $NB_GID {} \; \
26+
-exec chgrp "${NB_GID}" {} \; \
2727
-exec chmod g+rwX {} \;
2828
# setuid, setgid *on directories only*
2929
find "$d" \

base-notebook/start-notebook.sh

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@ if [[ "${RESTARTABLE}" == "yes" ]]; then
99
wrapper="run-one-constantly"
1010
fi
1111

12-
if [[ ! -z "${JUPYTERHUB_API_TOKEN}" ]]; then
12+
if [[ -n "${JUPYTERHUB_API_TOKEN}" ]]; then
1313
# launched by JupyterHub, use single-user entrypoint
1414
exec /usr/local/bin/start-singleuser.sh "$@"
15-
elif [[ ! -z "${JUPYTER_ENABLE_LAB}" ]]; then
15+
elif [[ -n "${JUPYTER_ENABLE_LAB}" ]]; then
16+
# shellcheck disable=SC1091
1617
. /usr/local/bin/start.sh $wrapper jupyter lab "$@"
1718
else
1819
echo "WARN: Jupyter Notebook deprecation notice https://github.com/jupyter/docker-stacks#jupyter-notebook-deprecation-notice."
20+
# shellcheck disable=SC1091
1921
. /usr/local/bin/start.sh $wrapper jupyter notebook "$@"
2022
fi

base-notebook/start-singleuser.sh

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,37 @@
55
set -e
66

77
# set default ip to 0.0.0.0
8-
if [[ "$NOTEBOOK_ARGS $@" != *"--ip="* ]]; then
8+
if [[ "$NOTEBOOK_ARGS $*" != *"--ip="* ]]; then
99
NOTEBOOK_ARGS="--ip=0.0.0.0 $NOTEBOOK_ARGS"
1010
fi
1111

1212
# handle some deprecated environment variables
1313
# from DockerSpawner < 0.8.
1414
# These won't be passed from DockerSpawner 0.9,
1515
# so avoid specifying --arg=empty-string
16-
if [ ! -z "$NOTEBOOK_DIR" ]; then
16+
if [ -n "$NOTEBOOK_DIR" ]; then
17+
# shellcheck disable=SC2089
1718
NOTEBOOK_ARGS="--notebook-dir='$NOTEBOOK_DIR' $NOTEBOOK_ARGS"
1819
fi
19-
if [ ! -z "$JPY_PORT" ]; then
20+
if [ -n "$JPY_PORT" ]; then
2021
NOTEBOOK_ARGS="--port=$JPY_PORT $NOTEBOOK_ARGS"
2122
fi
22-
if [ ! -z "$JPY_USER" ]; then
23+
if [ -n "$JPY_USER" ]; then
2324
NOTEBOOK_ARGS="--user=$JPY_USER $NOTEBOOK_ARGS"
2425
fi
25-
if [ ! -z "$JPY_COOKIE_NAME" ]; then
26+
if [ -n "$JPY_COOKIE_NAME" ]; then
2627
NOTEBOOK_ARGS="--cookie-name=$JPY_COOKIE_NAME $NOTEBOOK_ARGS"
2728
fi
28-
if [ ! -z "$JPY_BASE_URL" ]; then
29+
if [ -n "$JPY_BASE_URL" ]; then
2930
NOTEBOOK_ARGS="--base-url=$JPY_BASE_URL $NOTEBOOK_ARGS"
3031
fi
31-
if [ ! -z "$JPY_HUB_PREFIX" ]; then
32+
if [ -n "$JPY_HUB_PREFIX" ]; then
3233
NOTEBOOK_ARGS="--hub-prefix=$JPY_HUB_PREFIX $NOTEBOOK_ARGS"
3334
fi
34-
if [ ! -z "$JPY_HUB_API_URL" ]; then
35+
if [ -n "$JPY_HUB_API_URL" ]; then
3536
NOTEBOOK_ARGS="--hub-api-url=$JPY_HUB_API_URL $NOTEBOOK_ARGS"
3637
fi
3738
NOTEBOOK_BIN="jupyterhub-singleuser"
3839

39-
. /usr/local/bin/start.sh $NOTEBOOK_BIN $NOTEBOOK_ARGS "$@"
40+
# shellcheck disable=SC1091,SC2086,SC2090
41+
. /usr/local/bin/start.sh "$NOTEBOOK_BIN" $NOTEBOOK_ARGS "$@"

base-notebook/start.sh

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -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 () {
3940
run-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[@]}"
103106
else
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
@@ -110,7 +113,7 @@ else
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

@@ -142,6 +145,6 @@ else
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[@]}"
147150
fi

examples/docker-compose/bin/letsencrypt.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ set -e
1818

1919
# letsencrypt certificate server type (default is production).
2020
# Set `CERT_SERVER=--staging` for staging.
21-
: ${CERT_SERVER=''}
21+
: "${CERT_SERVER=''}"
2222

2323
# Create Docker volume to contain the cert
24-
: ${SECRETS_VOLUME:=my-notebook-secrets}
24+
: "${SECRETS_VOLUME:=my-notebook-secrets}"
2525
docker volume create --name $SECRETS_VOLUME 1>/dev/null
2626
# Generate the cert and save it to the Docker volume
2727
docker run --rm -it \

examples/docker-compose/bin/sl-dns.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ set -e
77
# User must have slcli installed
88
which slcli > /dev/null || (echo "SoftLayer cli not found (pip install softlayer)"; exit 1)
99

10-
USAGE="Usage: `basename $0` machine_name [domain]"
10+
USAGE="Usage: $(basename "$0") machine_name [domain]"
1111
E_BADARGS=85
1212

1313
# Machine name is first command line arg
@@ -20,4 +20,4 @@ DOMAIN="${2:-$SOFTLAYER_DOMAIN}" && [ -z "$DOMAIN" ] && \
2020

2121
IP=$(docker-machine ip "$MACHINE_NAME")
2222

23-
slcli dns record-add $DOMAIN $MACHINE_NAME A $IP
23+
slcli dns record-add "$DOMAIN" "$MACHINE_NAME" A "$IP"

examples/docker-compose/bin/softlayer.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
# Distributed under the terms of the Modified BSD License.
44

55
# Set default SoftLayer VM settings
6-
: ${SOFTLAYER_CPU:=4}
6+
: "${SOFTLAYER_CPU:=4}"
77
export SOFTLAYER_CPU
8-
: ${SOFTLAYER_DISK_SIZE:=100}
8+
: "${SOFTLAYER_DISK_SIZE:=100}"
99
export SOFTLAYER_DISK_SIZE
10-
: ${SOFTLAYER_MEMORY:=4096}
10+
: "${SOFTLAYER_MEMORY:=4096}"
1111
export SOFTLAYER_MEMORY
12-
: ${SOFTLAYER_REGION:=wdc01}
12+
: "${SOFTLAYER_REGION:=wdc01}"
1313
export SOFTLAYER_REGION
1414

1515
docker-machine create --driver softlayer "$@"

examples/docker-compose/bin/vbox.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
# Distributed under the terms of the Modified BSD License.
44

55
# Set reasonable default VM settings
6-
: ${VIRTUALBOX_CPUS:=4}
6+
: "${VIRTUALBOX_CPUS:=4}"
77
export VIRTUALBOX_CPUS
8-
: ${VIRTUALBOX_MEMORY_SIZE:=4096}
8+
: "${VIRTUALBOX_MEMORY_SIZE:=4096}"
99
export VIRTUALBOX_MEMORY_SIZE
1010

1111
docker-machine create --driver virtualbox "$@"

examples/docker-compose/notebook/build.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
66

77
# Setup environment
8+
# shellcheck disable=SC1091
89
source "$DIR/env.sh"
910

1011
# Build the notebook image

0 commit comments

Comments
 (0)