Skip to content

Commit 2d98df4

Browse files
authored
WPB-2568 Fix shellcheck linting problems on all shell scripts (#4220)
1 parent c11434b commit 2d98df4

34 files changed

+127
-154
lines changed

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,11 @@ add-license:
250250

251251
.PHONY: treefmt
252252
treefmt:
253-
treefmt -u debug
254-
253+
treefmt -u debug --walk=git
254+
255255
.PHONY: treefmt-check
256256
treefmt-check:
257-
treefmt --fail-on-change -u debug
257+
treefmt --fail-on-change -u debug --walk=git
258258

259259
#################################
260260
## docker targets
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix shellcheck problems in all shell scripts

changelog.d/mk-changelog.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ shopt -s nullglob
66
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
77

88
getPRNumber() {
9-
git log --reverse --format=%s -- $1 | sed -rn '1 { /\((#.*)\)$/ s|^.*\((#.*)\)$|\1|p; }' | grep "" ||
9+
git log --reverse --format=%s -- "$1" | sed -rn '1 { /\((#.*)\)$/ s|^.*\((#.*)\)$|\1|p; }' | grep "" ||
1010
echo "#PR_NOT_FOUND"
1111
}
1212

@@ -18,10 +18,12 @@ for d in "$DIR"/*; do
1818
if [[ ${#entries[@]} -eq 0 ]]; then continue; fi
1919

2020
echo -n "## "
21+
# shellcheck disable=SC1003
2122
sed '$ a\' "$d/.title"
2223
echo ""
2324
for f in "${entries[@]}"; do
24-
pr=$(getPRNumber $f)
25+
pr=$(getPRNumber "$f")
26+
# shellcheck disable=SC1003
2527
sed -r '
2628
# create a bullet point on the first line
2729
1 { s/^/\* /; }

deploy/dockerephemeral/init.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ aws configure set aws_secret_access_key dummysecret
1212
aws configure set region eu-west-1
1313

1414
# Potentially delete pre-existing tables
15-
echo -n "waiting for dynamo: "
15+
echo "waiting for dynamo: "
1616
while (! aws --endpoint-url=http://dynamodb:8000 --cli-connect-timeout=1 dynamodb list-tables); do
1717
sleep 1;
1818
done

hack/bin/cabal-run-tests.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ fi
1414
for cabal in $(find "$TOP_LEVEL" -name "$pattern" | grep -v dist-newstyle); do
1515
# This is required because some tests (e.g. golden tests) must be run from
1616
# the package root.
17-
cd "$(dirname $cabal)"
18-
package="$(basename ${cabal%.*})"
17+
cd "$(dirname "$cabal")"
18+
package="$(basename "${cabal%.*}")"
1919
for test_suite in $(cabal-plan list-bins "$package:test:*" | awk '{print $2}'); do
2020
$test_suite "${@:2}"
2121
done

hack/bin/copy-charts.sh

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,21 +9,21 @@ CHART=${1:?$USAGE}
99

1010
TOP_LEVEL="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"
1111
CHART_SOURCE=$TOP_LEVEL/charts
12-
CHART_DIST=$TOP_LEVEL/.local/charts
12+
CHART_DEST=$TOP_LEVEL/.local/charts
1313

1414
# TODO sanity check folder must exist
1515

1616
mkdir -p .local/charts
17-
rm -rf "$CHART_DIST/$CHART"
18-
cp -r "$CHART_SOURCE/$CHART" "$CHART_DIST/"
17+
rm -rf "${CHART_DEST:?}/$CHART"
18+
cp -r "$CHART_SOURCE/$CHART" "$CHART_DEST/"
1919

2020
if [ -f "$CHART_SOURCE/$CHART/requirements.yaml" ]; then
2121
# very hacky bash, I'm sorry
2222
for subpath in $(grep "file://" "$CHART_SOURCE/$CHART/requirements.yaml" | awk '{ print $2 }' | xargs -n 1 | cut -c 8-)
2323
do
24-
rm -rf "$CHART_DIST/$CHART/$subpath"
25-
cp -r "$CHART_SOURCE/$CHART/$subpath" "$CHART_DIST/"
24+
rm -rf "${CHART_DEST:?}/$CHART/$subpath"
25+
cp -r "$CHART_SOURCE/$CHART/$subpath" "$CHART_DEST/"
2626
done
2727
fi
2828

29-
echo "copied $CHART_SOURCE/$CHART (and its local dependencies) to $CHART_DIST/$CHART"
29+
echo "copied $CHART_SOURCE/$CHART (and its local dependencies) to $CHART_DEST/$CHART"

hack/bin/create_team_members.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ $ grep code out.log | grep -v email-exists
3333
3434
If you are in a hurry, you may want to change the sleep(1) at the end
3535
of the invite loop to less than a second. If you want to give up on
36-
the first error, add an exit(1) where we check the $INVIDATION_ID.
36+
the first error, add an exit(1) where we check the INVITATION_ID.
3737
3838
"
3939

hack/bin/create_test_team_admins.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@ fi
5151

5252
# Generate users
5353

54+
#shellcheck disable=SC2034
5455
for i in $(seq 1 "$COUNT")
5556
do
56-
EMAIL=$(cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 8)"@example.com"
57-
PASSWORD=$(cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 8)
57+
EMAIL=$(env LC_CTYPE=C tr -dc a-zA-Z0-9 < /dev/urandom | head -c 8)"@example.com"
58+
PASSWORD=$(env LC_CTYPE=C tr -dc a-zA-Z0-9 < /dev/urandom | head -c 8)
5859

5960
CURL_OUT=$(curl -i -s --show-error \
6061
-XPOST "$BRIG_HOST/i/users" \

hack/bin/create_test_team_members.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ END=$((COUNT + START - 1))
8484
for i in $(seq "$START" "$END")
8585
do
8686
EMAIL='w'$(printf "%03d" "$i")"@$TARGET_EMAIL_DOMAIN"
87-
PASSWORD=$(cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 8)
87+
PASSWORD=$(env LC_CTYPE=C tr -dc a-zA-Z0-9 < /dev/urandom | head -c 8)
8888

8989
# Generate the invitation
9090

@@ -125,7 +125,7 @@ do
125125

126126
if [ "$TEAM" != "$TEAM_UUID" ]; then
127127
echo "unexpected error: user got assigned to no / the wrong team?!"
128-
echo ${CURL_OUT}
128+
echo "${CURL_OUT}"
129129
exit 1
130130
fi
131131

hack/bin/create_test_team_scim.sh

+13-23
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ if [ "$#" -ne 0 ]; then
4545
fi
4646

4747

48-
ADMIN_EMAIL=$(cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 8)"@example.com"
49-
ADMIN_PASSWORD=$(cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 8)
48+
ADMIN_EMAIL=$(env LC_CTYPE=C tr -dc a-zA-Z0-9 < /dev/urandom | head -c 8)"@example.com"
49+
ADMIN_PASSWORD=$(env LC_CTYPE=C tr -dc a-zA-Z0-9 < /dev/urandom | head -c 8)
5050

5151
CURL_OUT=$(curl -i -s --show-error \
5252
-XPOST "$BRIG_HOST/i/users" \
@@ -61,23 +61,23 @@ BEARER=$(curl -X POST \
6161
--header 'Content-Type: application/json' \
6262
--header 'Accept: application/json' \
6363
-d '{"email":"'"$ADMIN_EMAIL"'","password":"'"$ADMIN_PASSWORD"'"}' \
64-
$BRIG_HOST/login'?persist=false' | jq -r .access_token)
64+
"$BRIG_HOST"/login'?persist=false' | jq -r .access_token)
6565

6666
SCIM_TOKEN_FULL=$(curl -X POST \
6767
--header "Authorization: Bearer $BEARER" \
6868
--header 'Content-Type: application/json;charset=utf-8' \
6969
--header 'Z-User: '"$ADMIN_UUID" \
70-
-d '{ "description": "test '"`date`"'", "password": "'"$ADMIN_PASSWORD"'" }' \
71-
$SPAR_HOST/scim/auth-tokens)
70+
-d '{ "description": "test '"$(date)"'", "password": "'"$ADMIN_PASSWORD"'" }' \
71+
"$SPAR_HOST/scim/auth-tokens")
7272

73-
SCIM_TOKEN=$(echo $SCIM_TOKEN_FULL | jq -r .token)
74-
SCIM_TOKEN_ID=$(echo $SCIM_TOKEN_FULL | jq -r .info.id)
73+
SCIM_TOKEN=$(echo "$SCIM_TOKEN_FULL" | jq -r .token)
74+
SCIM_TOKEN_ID=$(echo "$SCIM_TOKEN_FULL" | jq -r .info.id)
7575

7676

7777
# Create regular user via team invitation
7878

79-
REGULAR_USER_EMAIL=$(cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 8)"@example.com"
80-
REGULAR_USER_PASSWORD=$(cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 8)
79+
REGULAR_USER_EMAIL=$(env LC_CTYPE=C tr -dc a-zA-Z0-9 < /dev/urandom | head -c 8)"@example.com"
80+
REGULAR_USER_PASSWORD=$(env LC_CTYPE=C tr -dc a-zA-Z0-9 < /dev/urandom | head -c 8)
8181
CURL_OUT_INVITATION=$(curl -i -s --show-error \
8282
-XPOST "$BRIG_HOST/teams/$TEAM_UUID/invitations" \
8383
-H'Content-type: application/json' \
@@ -122,7 +122,7 @@ REGULAR_TEAM_MEMBER_UUID=$(echo "$CURL_OUT" | tail -1 | sed 's/.*\"id\":\"\([a-z
122122
# Create user via SCIM invitation
123123

124124

125-
scimUserName=$(cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 8)
125+
scimUserName=$(env LC_CTYPE=C tr -dc a-zA-Z0-9 < /dev/urandom | head -c 8)
126126
scimUserDisplayName="Display of $scimUserName"
127127
scimUserEmail="$scimUserName@example.com"
128128
scimUserExternalId="$scimUserEmail"
@@ -156,7 +156,7 @@ CURL_OUT_SCIM_POST=$(curl --location --request POST "$SPAR_HOST/scim/v2/Users" \
156156
--header "Authorization: Bearer $SCIM_TOKEN" \
157157
-d "$SCIM_USER")
158158

159-
SCIM_USER_UUID=$(echo $CURL_OUT_SCIM_POST | jq -r .id)
159+
SCIM_USER_UUID=$(echo "$CURL_OUT_SCIM_POST" | jq -r .id)
160160

161161
SCIM_USER_INVITATION_ID=$(curl --location -G "$BRIG_HOST/i/teams/invitations/by-email?" \
162162
--header 'Content-Type: application/json' \
@@ -170,17 +170,7 @@ SCIM_USER_INVITATION_CODE=$(curl --silent --show-error \
170170
-XGET "$BRIG_HOST/i/teams/invitation-code?team=$TEAM_UUID&invitation_id=$SCIM_USER_INVITATION_ID" | jq -r .code
171171
)
172172

173-
scimUserPassword=$(cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 8)
174-
175-
REGISTER_ACCEPT=$(cat <<EOF
176-
{
177-
"name": "$scimUserDisplayName",
178-
"email": "$scimUserEmail",
179-
"password": "$scimUserPassword",
180-
"team_code": "$SCIM_USER_INVITATION_CODE"
181-
}
182-
EOF
183-
)
173+
scimUserPassword=$(env LC_CTYPE=C tr -dc a-zA-Z0-9 < /dev/urandom | head -c 8)
184174

185175
# Create the user using that code
186176
CURL_OUT=$(curl \
@@ -192,7 +182,7 @@ SCIM_USER_REGISTER_TEAM=$(echo "$CURL_OUT" | jq -r .team)
192182

193183
if [ "$SCIM_USER_REGISTER_TEAM" != "$TEAM_UUID" ]; then
194184
echo "unexpected error: user got assigned to no / the wrong team?!"
195-
echo ${CURL_OUT}
185+
echo "${CURL_OUT}"
196186
exit 1
197187
fi
198188

hack/bin/create_test_user.sh

+7-6
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,21 @@ fi;
4747

4848
# Generate users
4949

50-
for i in `seq 1 $COUNT`
50+
# shellcheck disable=SC2034
51+
for i in $(seq 1 "$COUNT")
5152
do
52-
EMAIL=$(cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 8)"@example.com"
53-
PASSWORD=$(cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 8)
53+
EMAIL=$(env LC_CTYPE=C tr -dc a-zA-Z0-9 < /dev/urandom | head -c 8)"@example.com"
54+
PASSWORD=$(env LC_CTYPE=C tr -dc a-zA-Z0-9 < /dev/urandom | head -c 8)
5455

5556
CURL_OUT=$(curl -i -s --show-error \
5657
-XPOST "$BRIG_HOST/i/users" \
5758
-H'Content-type: application/json' \
58-
-d'{"email":"'$EMAIL'","password":"'$PASSWORD'","name":"demo"}')
59+
-d'{"email":"'"$EMAIL"'","password":"'"$PASSWORD"'","name":"demo"}')
5960

6061
UUID=$(echo "$CURL_OUT" | tail -1 | sed 's/.*\"id\":\"\([a-z0-9-]*\)\".*/\1/')
6162

6263
if [ "$CSV" == "false" ]
63-
then echo -e "Succesfully created a user with email: "$EMAIL" and password: "$PASSWORD
64-
else echo -e $UUID","$EMAIL","$PASSWORD
64+
then echo -e "Succesfully created a user with email: ""$EMAIL"" and password: ""$PASSWORD"
65+
else echo -e "$UUID,$EMAIL,$PASSWORD"
6566
fi
6667
done

hack/bin/diff-failure.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
sed 's| =/= |\n|' | {
3-
IFS= read first
4-
IFS= read second
3+
IFS= read -r first
4+
IFS= read -r second
55
exec wdiff -n -w $'\033[30;41m' -x $'\033[0m' \
66
-y $'\033[30;42m' -z $'\033[0m' \
77
<(echo "$first") <(echo "$second")

hack/bin/helm-template.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ if [ -f "$certificatesfile" ]; then
2525
fi
2626

2727
"$DIR/update.sh" "$CHARTS_DIR/$chart"
28-
helm template $"chart" "$CHARTS_DIR/$chart" ${options[*]}
28+
helm template "$chart" "$CHARTS_DIR/$chart" "${options[*]}"

hack/bin/integration-setup-federation.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ HELMFILE_ENV=${HELMFILE_ENV:-default}
1010
CHARTS_DIR="${TOP_LEVEL}/.local/charts"
1111
HELM_PARALLELISM=${HELM_PARALLELISM:-1}
1212

13+
# shellcheck disable=SC1091
1314
. "$DIR/helm_overrides.sh"
14-
${DIR}/integration-cleanup.sh
15+
"${DIR}"/integration-cleanup.sh
1516

1617
# FUTUREWORK explore: have helmfile do the interpolation (and skip the "make charts" step) https://wearezeta.atlassian.net/browse/SQPIT-722
1718
#
-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
#!/usr/bin/env bash
22

3-
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/.."
4-
53
set -x
64

75
IFS=$'\n'
86
for NAMESPACE in $(kubectl get namespaces | grep "^test-" | awk '{print $1}'); do
9-
107
echo "$NAMESPACE"
118
kubectl delete namespace "$NAMESPACE" &
12-
139
done

hack/bin/integration-teardown-federation.sh

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ else
2424
export INGRESS_CHART="nginx-ingress-controller"
2525
fi
2626

27+
# shellcheck disable=SC1091
2728
. "$DIR/helm_overrides.sh"
2829
helmfile --environment "$HELMFILE_ENV" --file "${TOP_LEVEL}/hack/helmfile.yaml" destroy --skip-deps --skip-charts --concurrency 0 || echo "Failed to delete helm deployments, ignoring this failure as next steps will the destroy namespaces anyway."
2930

hack/bin/integration-test-logs.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ if [[ -z "$NAMESPACE" ]]; then
66
exit 1
77
fi
88

9-
while IFS= read LINE; do
9+
while IFS= read -r LINE; do
1010
if [[ "$LINE" =~ ^Pod\ (.*)\ running$ ]]; then
1111
kubectl -n "$NAMESPACE" logs "${BASH_REMATCH[1]}" -f
1212
fi

hack/bin/register_idp_internal.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ if [ ! -e "${metadata_file}" ]; then
1414
fi
1515

1616
z_user=$2
17-
if [ ! -n "${z_user}" ]; then
17+
if [ -z "${z_user}" ]; then
1818
echo "*** no z_user uuid"
1919
exit 80
2020
fi

hack/bin/serve-charts.sh

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22

33
set -euo pipefail
44

5-
: ${HELM_SERVER_PORT:=4001}
5+
: "${HELM_SERVER_PORT:=4001}"
66

77
# get rid of all helm repositories
88
# We need to deal with helm repo list failing because of https://github.com/helm/helm/issues/10028
99
(helm repo list -o json || echo '[]') | jq -r '.[] | .name' | xargs -I% helm repo remove %
1010

11-
cd "$(dirname "$BASH_SOURCE[0]")/../../.local/charts"
12-
for chart in $@; do
11+
SCRIPT_DIR=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
12+
cd "$SCRIPT_DIR/../../.local/charts"
13+
14+
for chart in "$@"; do
1315
../../hack/bin/update.sh "$chart"
1416
helm package "$chart"
1517
done
1618
helm repo index .
17-
python3 -m http.server $HELM_SERVER_PORT
19+
python3 -m http.server "$HELM_SERVER_PORT"

hack/bin/set-chart-image-version.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
USAGE="$0 <docker-tag> <chart-name>..."
44
docker_tag=${1?$USAGE}
5-
charts=${@:2}
5+
charts=${*:2}
66

77
TOP_LEVEL="$( cd "$( dirname "${BASH_SOURCE[0]}" )/../.." && pwd )"
88
CHARTS_DIR="$TOP_LEVEL/.local/charts"

hack/bin/set-helm-chart-version.sh

+1-2
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ function write_versions() {
2424
# update all dependencies, if any
2525
if [ -a requirements.yaml ]; then
2626
sed -e "s/ version: \".*\"/ version: \"$target_version\"/g" requirements.yaml > "$tempfile" && mv "$tempfile" requirements.yaml
27-
deps=( $(helm dependency list | grep -v NAME | awk '{print $1}') )
28-
for dep in "${deps[@]}"; do
27+
for dep in $(helm dependency list | grep -v NAME | awk '{print $1}'); do
2928
if [ -d "$CHARTS_DIR/$dep" ] && [ "$chart" != "$dep" ]; then
3029
(cd "$CHARTS_DIR/$dep" && write_versions "$target_version")
3130
fi

hack/bin/upload-helm-charts-s3.sh

+3-2
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,11 @@ cd "$TOP_LEVEL_DIR"
114114

115115
# If ./upload-helm-charts-s3.sh is run with a parameter, only synchronize one chart
116116
if [ -n "$chart_dir" ] && [ -d "$chart_dir" ]; then
117-
chart_name=$(basename $chart_dir)
117+
chart_name=$(basename "$chart_dir")
118118
echo "only syncing $chart_name"
119119
charts=( "$chart_name" )
120120
else
121+
#shellcheck disable=SC2207
121122
charts=( $(make -s -C "$TOP_LEVEL_DIR" echo-release-charts) )
122123
# See Makefile/ CHARTS_RELEASE FUTUREWORK
123124
#charts=( $(find $CHART_DIR/ -maxdepth 1 -type d | sed -n "s=$CHART_DIR/\(.\+\)=\1 =p") )
@@ -176,7 +177,7 @@ if [[ "$reindex" == "1" ]]; then
176177
else
177178
# update local cache with newly pushed charts
178179
helm repo update
179-
printf "\n--> Not reindexing by default. Pass the --reindex flag in case the index.yaml is incomplete. See all wire charts using \n helm search repo $REPO_NAME/ -l\n\n"
180+
printf "\n--> Not reindexing by default. Pass the --reindex flag in case the index.yaml is incomplete. See all wire charts using \n helm search repo %s/ -l\n\n" "$REPO_NAME"
180181
fi
181182

182183

0 commit comments

Comments
 (0)