Skip to content

Commit 384d741

Browse files
williamspatrickgeissonator
authored andcommitted
shellcheck: clean up shellcheck warnings and enable
Signed-off-by: Patrick Williams <[email protected]> Change-Id: Ibc843b98c0fea97a31d3d15b556a32f091bf8e47
1 parent 7a6b382 commit 384d741

22 files changed

+249
-235
lines changed

Diff for: .shellcheck

Whitespace-only changes.

Diff for: build-jenkins.sh

+34-30
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ launch=${launch:-docker}
9191
j_url=https://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkins-war/${j_vrsn}/jenkins-war-${j_vrsn}.war
9292

9393
# Make or Clean WORKSPACE
94-
if [[ -d ${workspace} ]]; then
95-
rm -rf ${workspace}/Dockerfile \
96-
${workspace}/docker-jenkins \
97-
${workspace}/plugins.* \
98-
${workspace}/install-plugins.sh \
99-
${workspace}/jenkins.sh \
100-
${workspace}/jenkins-support \
101-
${workspace}/init.groovy
94+
if [[ -d "${workspace}" ]]; then
95+
rm -rf "${workspace}/Dockerfile" \
96+
"${workspace}/docker-jenkins" \
97+
"${workspace}/plugins.*" \
98+
"${workspace}/install-plugins.sh" \
99+
"${workspace}/jenkins.sh" \
100+
"${workspace}/jenkins-support" \
101+
"${workspace}/init.groovy"
102102
else
103-
mkdir -p ${workspace}
103+
mkdir -p "${workspace}"
104104
fi
105105

106106
# Determine the prefix of the Dockerfile's base image
@@ -119,7 +119,7 @@ case ${ARCH} in
119119
esac
120120

121121
# Move Into the WORKSPACE
122-
cd ${workspace}
122+
cd "${workspace}"
123123

124124
# Make the Dockerfile
125125
################################################################################
@@ -200,31 +200,33 @@ EOF
200200
################################################################################
201201

202202
# Build the image
203-
docker build -t ${img_name} .
203+
docker build -t "${img_name}" .
204204

205-
if [[ ${launch} == "docker" ]]; then
205+
if [[ "${launch}" == "docker" ]]; then
206206

207207
# Ensure directories that will be mounted exist
208-
if [[ ! -z ${host_import_mnt} && ! -d ${host_import_mnt} ]]; then
209-
mkdir -p ${host_import_mnt}
208+
if [[ -n "${host_import_mnt}" && ! -d "${host_import_mnt}" ]]; then
209+
mkdir -p "${host_import_mnt}"
210210
fi
211211

212-
if [[ ! -d ${home_mnt} ]]; then
213-
mkdir -p ${home_mnt}
212+
if [[ ! -d "${home_mnt}" ]]; then
213+
mkdir -p "${home_mnt}"
214214
fi
215215

216216
# Ensure directories that will be mounted are owned by the jenkins user
217217
if [[ "$(id -u)" != 0 ]]; then
218218
echo "Not running as root:"
219219
echo "Checking if j_gid and j_uid are the owners of mounted directories"
220-
test_1=$(ls -nd ${home_mnt} | awk '{print $3 " " $4}')
220+
# shellcheck disable=SC2012 # use ls to get permissions.
221+
test_1="$(ls -nd "${home_mnt}" | awk '{print $3 " " $4}')"
221222
if [[ "${test_1}" != "${j_uid} ${j_gid}" ]]; then
222223
echo "Owner of ${home_mnt} is not the jenkins user"
223224
echo "${test_1} != ${j_uid} ${j_gid}"
224225
will_fail=1
225226
fi
226-
if [[ ! -z "${host_import_mnt}" ]]; then
227-
test_2=$(ls -nd ${host_import_mnt} | awk '{print $3 " " $4}' )
227+
if [[ -n "${host_import_mnt}" ]]; then
228+
# shellcheck disable=SC2012 # use ls to get permissions.
229+
test_2="$(ls -nd "${host_import_mnt}" | awk '{print $3 " " $4}' )"
228230
if [[ "${test_2}" != "${j_uid} ${j_gid}" ]]; then
229231
echo "Owner of ${host_import_mnt} is not the jenkins user"
230232
echo "${test_2} != ${j_uid} ${j_gid}"
@@ -237,27 +239,29 @@ if [[ ${launch} == "docker" ]]; then
237239
exit 1
238240
fi
239241
else
240-
if [[ ! -z ${host_import_mnt} ]]; then
241-
chown -R ${j_uid}:${j_gid} ${host_import_mnt}
242+
if [[ -n "${host_import_mnt}" ]]; then
243+
chown -R "${j_uid}:${j_gid}" "${host_import_mnt}"
242244
fi
243-
chown -R ${j_uid}:${j_gid} ${home_mnt}
245+
chown -R "${j_uid}:${j_gid}" "${home_mnt}"
244246
fi
245247

246248
#If we don't have import mount don't add to docker command
247-
if [[ ! -z ${host_import_mnt} ]]; then
249+
if [[ -n "${host_import_mnt}" ]]; then
248250
import_vol_cmd="-v ${host_import_mnt}:${cont_import_mnt}"
249251
fi
250252
# Launch the jenkins image with Docker
253+
# shellcheck disable=SC2086 # import_vol_cmd is intentially word-split.
251254
docker run -d \
252255
${import_vol_cmd} \
253-
-v ${home_mnt}:${j_home} \
254-
-p ${http_port}:8080 \
255-
-p ${agent_port}:${agent_port} \
256-
--env JAVA_OPTS=\"${java_options}\" \
257-
--env JENKINS_OPTS=\"${jenkins_options}\" \
258-
${img_name}
256+
-v "${home_mnt}:${j_home}" \
257+
-p "${http_port}:8080" \
258+
-p "${agent_port}:${agent_port}" \
259+
--env JAVA_OPTS=\""${java_options}"\" \
260+
--env JENKINS_OPTS=\""${jenkins_options}"\" \
261+
"${img_name}"
259262

260263
elif [[ ${launch} == "k8s" ]]; then
261264
# launch using the k8s template
262-
source ${build_scripts_dir}/kubernetes/kubernetes-launch.sh Build-Jenkins false false
265+
# shellcheck source=kubernetes/kubernetes-launch.sh
266+
source "${build_scripts_dir}/kubernetes/kubernetes-launch.sh" Build-Jenkins false false
263267
fi

Diff for: build-rootfs-size-docker.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ RUN apt-get update && apt-get install -yy \
4949
squashfs-tools
5050
5151
# Final configuration for the workspace
52-
RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
53-
RUN mkdir -p $(dirname ${HOME})
54-
RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
52+
RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
53+
RUN mkdir -p $(dirname "${HOME}")
54+
RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
5555
RUN sed -i '1iDefaults umask=000' /etc/sudoers
5656
RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
5757
@@ -62,4 +62,4 @@ fi
6262
################################# docker img # #################################
6363

6464
# Build above image
65-
docker build --network=host -t ${DOCKER_IMG_NAME} - <<< "${Dockerfile}"
65+
docker build --network=host -t "${DOCKER_IMG_NAME}" - <<< "${Dockerfile}"

Diff for: build-setup.sh

+19-18
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,16 @@ esac
133133
echo "Build started, $(date)"
134134

135135
# If the obmc_dir directory doesn't exist clone it in
136-
if [ ! -d ${obmc_dir} ]; then
136+
if [ ! -d "${obmc_dir}" ]; then
137137
echo "Clone in openbmc master to ${obmc_dir}"
138-
git clone https://github.com/openbmc/openbmc ${obmc_dir}
138+
git clone https://github.com/openbmc/openbmc "${obmc_dir}"
139139
fi
140140

141141
# Make and chown the xtrct_path directory to avoid permission errors
142-
if [ ! -d ${xtrct_path} ]; then
143-
mkdir -p ${xtrct_path}
142+
if [ ! -d "${xtrct_path}" ]; then
143+
mkdir -p "${xtrct_path}"
144144
fi
145-
chown ${UID}:${GROUPS} ${xtrct_path}
145+
chown "${UID}:${GROUPS[0]}" "${xtrct_path}"
146146

147147
# Work out what build target we should be running and set BitBake command
148148
MACHINE=""
@@ -264,8 +264,8 @@ if [[ "${distro}" == fedora ]];then
264264
ENV LANG=en_US.utf8
265265
RUN localedef -f UTF-8 -i en_US en_US.UTF-8
266266
267-
RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
268-
RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
267+
RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
268+
RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
269269
270270
USER ${USER}
271271
ENV HOME ${HOME}
@@ -313,8 +313,8 @@ elif [[ "${distro}" == ubuntu ]]; then
313313
ENV LANGUAGE en_US:en
314314
ENV LC_ALL en_US.UTF-8
315315
316-
RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
317-
RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
316+
RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
317+
RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
318318
319319
USER ${USER}
320320
ENV HOME ${HOME}
@@ -328,10 +328,10 @@ export PROXY_HOST=${http_proxy/#http*:\/\/}
328328
export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
329329
export PROXY_PORT=${http_proxy/#http*:\/\/*:}
330330

331-
mkdir -p ${WORKSPACE}
331+
mkdir -p "${WORKSPACE}"
332332

333333
# Determine command for bitbake image build
334-
if [ $no_tar = "false" ]; then
334+
if [ "$no_tar" = "false" ]; then
335335
bitbake_target="${bitbake_target} obmc-phosphor-debug-tarball"
336336
fi
337337

@@ -438,13 +438,13 @@ fi
438438
439439
EOF_SCRIPT
440440

441-
chmod a+x ${WORKSPACE}/build.sh
441+
chmod a+x "${WORKSPACE}/build.sh"
442442

443443
# Give the Docker image a name based on the distro,tag,arch,and target
444444
img_name=${img_name:-openbmc/${distro}:${img_tag}-${target}-${ARCH}}
445445

446446
# Build the Docker image
447-
docker build -t ${img_name} - <<< "${Dockerfile}"
447+
docker build -t "${img_name}" - <<< "${Dockerfile}"
448448

449449
# If obmc_dir or ssc_dir are ${HOME} or a subdirectory they will not be mounted
450450
mount_obmc_dir="-v ""${obmc_dir}"":""${obmc_dir}"" "
@@ -461,23 +461,24 @@ mount_workspace_dir=""
461461
fi
462462

463463
# Run the Docker container, execute the build.sh script
464+
# shellcheck disable=SC2086 # mount commands word-split purposefully
464465
docker run \
465466
--cap-add=sys_admin \
466467
--cap-add=sys_nice \
467468
--net=host \
468469
--rm=true \
469-
-e WORKSPACE=${WORKSPACE} \
470+
-e WORKSPACE="${WORKSPACE}" \
470471
-w "${HOME}" \
471-
-v "${HOME}":"${HOME}" \
472+
-v "${HOME}:${HOME}" \
472473
${mount_obmc_dir} \
473474
${mount_ssc_dir} \
474475
${mount_workspace_dir} \
475476
--cpus="$num_cpu" \
476-
-t ${img_name} \
477-
${WORKSPACE}/build.sh
477+
-t "${img_name}" \
478+
"${WORKSPACE}/build.sh"
478479

479480
# To maintain function of resources that used an older path, add a link
480-
ln -sf ${xtrct_path}/deploy ${WORKSPACE}/deploy
481+
ln -sf "${xtrct_path}/deploy" "${WORKSPACE}/deploy"
481482

482483
# Timestamp for build
483484
echo "Build completed, $(date)"

Diff for: build-unit-test-docker.sh

+9-7
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ generate_depcache_entry() {
7575
grep "refs/heads/$BRANCH" | awk '{ print $1 }' || true)
7676

7777
# If specific branch is not found then try master
78-
if [[ ! -n "$tip" ]]; then
78+
if [[ -z "$tip" ]]; then
7979
tip=$(git ls-remote --heads "https://github.com/${package}" |
8080
grep "refs/heads/master" | awk '{ print $1 }')
8181
fi
@@ -123,10 +123,11 @@ declare -A PKG_REV=(
123123
)
124124

125125
# Turn the depcache into a dictionary so we can reference the HEAD of each repo
126-
for line in $(cat "$DEPCACHE_FILE"); do
126+
while IFS= read -r line; do
127+
# shellcheck disable=SC2207 # Expecting to word-split tr results.
127128
linearr=($(echo "$line" | tr ':' ' '))
128129
PKG_REV["${linearr[0]}"]="${linearr[1]}"
129-
done
130+
done < "$DEPCACHE_FILE"
130131

131132
# Define common flags used for builds
132133
PREFIX="/usr/local"
@@ -159,7 +160,7 @@ COPY_CMDS=""
159160
# We must sort the packages, otherwise we might produce an unstable
160161
# docker file and rebuild the image unnecessarily
161162
for pkg in $(echo "${!PKG_REV[@]}" | tr ' ' '\n' | LC_COLLATE=C sort -s); do
162-
COPY_CMDS+="COPY --from=$(stagename ${pkg}) ${PREFIX} ${PREFIX}"$'\n'
163+
COPY_CMDS+="COPY --from=$(stagename "${pkg}") ${PREFIX} ${PREFIX}"$'\n'
163164
# Workaround for upstream docker bug and multiple COPY cmds
164165
# https://github.com/moby/moby/issues/37965
165166
COPY_CMDS+="RUN true"$'\n'
@@ -498,9 +499,9 @@ ${COPY_CMDS}
498499
RUN echo '$(LC_COLLATE=C sort -s "$DEPCACHE_FILE" | tr '\n' ',')' > /tmp/depcache
499500
500501
# Final configuration for the workspace
501-
RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
502+
RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
502503
RUN mkdir -p "$(dirname "${HOME}")"
503-
RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
504+
RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
504505
RUN sed -i '1iDefaults umask=000' /etc/sudoers
505506
RUN echo "${USER} ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
506507
@@ -517,4 +518,5 @@ if [[ -n "${http_proxy}" ]]; then
517518
fi
518519

519520
# Build above image
520-
docker build ${proxy_args} --network=host -t ${DOCKER_IMG_NAME} - <<< "${Dockerfile}"
521+
# shellcheck disable=SC2086 # proxy_args requires word splitting.
522+
docker build ${proxy_args} --network=host -t "${DOCKER_IMG_NAME}" - <<< "${Dockerfile}"

Diff for: docs-build.sh

+8-9
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ FROM ubuntu:16.04
2323
2424
${PROXY}
2525
26-
ENV DEBIAN_FRONTEND noninteractive
26+
ENV DEBIAN_FRONTEND noninteractive
2727
RUN apt-get update && apt-get install -yy \
2828
make \
2929
texlive-xetex \
3030
pandoc \
3131
fonts-inconsolata \
3232
fonts-linuxlibertine
3333
34-
RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
35-
RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
34+
RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
35+
RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
3636
3737
USER ${USER}
3838
ENV HOME ${HOME}
@@ -41,8 +41,7 @@ EOF
4141
)
4242

4343
# Build the docker container
44-
docker build -t linux-build/ubuntu - <<< "${Dockerfile}"
45-
if [[ "$?" -ne 0 ]]; then
44+
if ! docker build -t linux-build/ubuntu - <<< "${Dockerfile}" ; then
4645
echo "Failed to build docker container."
4746
exit 1
4847
fi
@@ -52,7 +51,7 @@ export PROXY_HOST=${http_proxy/#http*:\/\/}
5251
export PROXY_HOST=${PROXY_HOST/%:[0-9]*}
5352
export PROXY_PORT=${http_proxy/#http*:\/\/*:}
5453

55-
mkdir -p ${WORKSPACE}
54+
mkdir -p "${WORKSPACE}"
5655

5756
cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
5857
#!/bin/bash
@@ -68,8 +67,8 @@ make
6867
6968
EOF_SCRIPT
7069

71-
chmod a+x ${WORKSPACE}/build.sh
70+
chmod a+x "${WORKSPACE}/build.sh"
7271

7372
# Run the docker container, execute the build script we just built
74-
docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE=${WORKSPACE} --user="${USER}" \
75-
-w "${HOME}" -v "${HOME}":"${HOME}" -t linux-build/ubuntu ${WORKSPACE}/build.sh
73+
docker run --cap-add=sys_admin --net=host --rm=true -e WORKSPACE="${WORKSPACE}" --user="${USER}" \
74+
-w "${HOME}" -v "${HOME}":"${HOME}" -t linux-build/ubuntu "${WORKSPACE}/build.sh"

Diff for: initramfs-build.sh

+4-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55

66
# Debug
7-
if grep -q debug <<< $@; then
7+
if grep -q debug <<< "$@"; then
88
set -x
99
fi
1010
set -o errexit
@@ -84,8 +84,8 @@ RUN apt-get update && apt-get install -yy \
8484
iputils-ping \
8585
locales
8686
87-
RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
88-
RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
87+
RUN grep -q ${GROUPS[0]} /etc/group || groupadd -g ${GROUPS[0]} ${USER}
88+
RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS[0]} ${USER}
8989
9090
RUN locale-gen en_AU.utf8
9191
@@ -96,8 +96,7 @@ EOF
9696
)
9797

9898
# Build the docker container
99-
docker build -t initramfs-build/ubuntu - <<< "${Dockerfile}"
100-
if [[ "$?" -ne 0 ]]; then
99+
if ! docker build -t initramfs-build/ubuntu - <<< "${Dockerfile}" ; then
101100
echo "Failed to build docker container."
102101
exit 1
103102
fi

0 commit comments

Comments
 (0)