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 6af1e69
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,13 @@ 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 \
--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
15 changes: 8 additions & 7 deletions _test_tools/ncsvr/ncsvr.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
# See the License for the specific language governing permissions and
# 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 6af1e69

Please sign in to comment.