Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lint for shellcheck, fix issues #907

Merged
merged 1 commit into from
Jul 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading