Skip to content

Commit 6af1e69

Browse files
committed
Add lint for shellcheck, fix issues
1 parent 458a7e5 commit 6af1e69

File tree

3 files changed

+21
-11
lines changed

3 files changed

+21
-11
lines changed

Makefile

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,13 @@ lint-staticcheck:
283283
lint-golangci-lint:
284284
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.0 run
285285

286-
lint: lint-staticcheck lint-golangci-lint
286+
lint-shellcheck:
287+
docker run \
288+
--rm \
289+
-v `pwd`:`pwd` \
290+
-w `pwd` \
291+
docker.io/koalaman/shellcheck-alpine:v0.9.0 \
292+
shellcheck \
293+
$$(git ls-files ':!:vendor' '*.sh')
294+
295+
lint: lint-staticcheck lint-golangci-lint lint-shellcheck

_test_tools/git_askpass.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/bin/sh
1+
#!/bin/bash
22
#
33
# Copyright 2019 The Kubernetes Authors.
44
#
@@ -20,15 +20,15 @@ set -o errexit
2020
set -o nounset
2121

2222
# Ask pass some ops, fail if it mismatched the magic password.
23-
if [ "$1" = "clone" -o "$1" = "ls-remote" -o "$1" = "fetch" ]; then
23+
if [[ "$1" == "clone" || "$1" == "ls-remote" || "$1" = "fetch" ]]; then
2424
# `git credential fill` requires the repo url match to consume the credentials stored by git-sync.
2525
# Askpass git only support repo started with "file://" which is used in test_e2e.sh.
2626
REPO=$(echo "$@" | grep -o "file://[^ ]*")
2727
OUTPUT=$(echo "url=${REPO}" | git credential fill)
2828
USERNAME=$(echo "${OUTPUT}" | grep "^username=.*")
2929
PASSWD=$(echo "${OUTPUT}" | grep "^password=.*")
3030
# Test case must match the magic username and password below.
31-
if [ "${USERNAME}" != "username=my-username" -o "${PASSWD}" != "password=my-password" ]; then
31+
if [[ "${USERNAME}" != "username=my-username" || "${PASSWD}" != "password=my-password" ]]; then
3232
echo "invalid test username/password pair: ${USERNAME}:${PASSWD}"
3333
exit 1
3434
fi

_test_tools/ncsvr/ncsvr.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,18 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
18-
if [ -z "$1" -o -z "$2" ]; then
17+
if [ -z "$1" ] || [ -z "$2" ]; then
1918
echo "usage: $0 <port> <shell-command>"
2019
exit 1
2120
fi
2221

23-
F="/tmp/fifo.$RANDOM"
24-
22+
# This construction allows the passed-in command ($2) to optionally read from
23+
# the client before responding (e.g. an HTTP request).
24+
CMD_TO_NC=$(mktemp -u)
25+
NC_TO_CMD=$(mktemp -u)
26+
mkfifo "$CMD_TO_NC" "$NC_TO_CMD"
2527
while true; do
26-
rm -f "$F"
27-
mkfifo "$F"
28-
cat "$F" | sh -c "$2" 2>&1 | nc -l -p "$1" -N -w1 > "$F"
28+
sh -c "$2" > "$CMD_TO_NC" 2>&1 < "$NC_TO_CMD" &
29+
nc -l -p "$1" -N -w1 < "$CMD_TO_NC" > "$NC_TO_CMD"
2930
date >> /var/log/hits
3031
done

0 commit comments

Comments
 (0)