Skip to content

Commit

Permalink
Add lint for shellcheck, fix issues
Browse files Browse the repository at this point in the history
  • Loading branch information
thockin committed Jul 4, 2024
1 parent 458a7e5 commit ce8c257
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,14 @@ lint-staticcheck:
lint-golangci-lint:
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.0 run

lint: lint-staticcheck lint-golangci-lint
lint-shellcheck:
docker run \
-it \
--rm \
-v `pwd`:`pwd` \
-w `pwd` \
docker.io/koalaman/shellcheck-alpine:v0.9.0 \
shellcheck \
$$(git ls-files ':!:vendor' '*.sh')

lint: lint-staticcheck lint-golangci-lint lint-shellcheck
6 changes: 3 additions & 3 deletions _test_tools/git_askpass.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
#
# Copyright 2019 The Kubernetes Authors.
#
Expand All @@ -20,15 +20,15 @@ set -o errexit
set -o nounset

# Ask pass some ops, fail if it mismatched the magic password.
if [ "$1" = "clone" -o "$1" = "ls-remote" -o "$1" = "fetch" ]; then
if [[ "$1" == "clone" || "$1" == "ls-remote" || "$1" = "fetch" ]]; then
# `git credential fill` requires the repo url match to consume the credentials stored by git-sync.
# Askpass git only support repo started with "file://" which is used in test_e2e.sh.
REPO=$(echo "$@" | grep -o "file://[^ ]*")
OUTPUT=$(echo "url=${REPO}" | git credential fill)
USERNAME=$(echo "${OUTPUT}" | grep "^username=.*")
PASSWD=$(echo "${OUTPUT}" | grep "^password=.*")
# Test case must match the magic username and password below.
if [ "${USERNAME}" != "username=my-username" -o "${PASSWD}" != "password=my-password" ]; then
if [[ "${USERNAME}" != "username=my-username" || "${PASSWD}" != "password=my-password" ]]; then
echo "invalid test username/password pair: ${USERNAME}:${PASSWD}"
exit 1
fi
Expand Down
14 changes: 8 additions & 6 deletions _test_tools/ncsvr/ncsvr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@
# limitations under the License.


if [ -z "$1" -o -z "$2" ]; then
if [ -z "$1" ] || [ -z "$2" ]; then
echo "usage: $0 <port> <shell-command>"
exit 1
fi

F="/tmp/fifo.$RANDOM"

# This construction allows the passed-in command ($2) to optionally read from
# the client before responding (e.g. an HTTP request).
CMD_TO_NC=$(mktemp -u)
NC_TO_CMD=$(mktemp -u)
mkfifo "$CMD_TO_NC" "$NC_TO_CMD"
while true; do
rm -f "$F"
mkfifo "$F"
cat "$F" | sh -c "$2" 2>&1 | nc -l -p "$1" -N -w1 > "$F"
sh -c "$2" > "$CMD_TO_NC" 2>&1 < "$NC_TO_CMD" &
nc -l -p "$1" -N -w1 < "$CMD_TO_NC" > "$NC_TO_CMD"
date >> /var/log/hits
done

0 comments on commit ce8c257

Please sign in to comment.