Add lint for shellcheck, fix issues

This commit is contained in:
Tim Hockin 2024-06-28 12:03:20 -07:00
parent 458a7e5c97
commit ffe08a6b4b
No known key found for this signature in database
3 changed files with 21 additions and 11 deletions

View File

@ -283,4 +283,13 @@ lint-staticcheck:
lint-golangci-lint: lint-golangci-lint:
go run github.com/golangci/golangci-lint/cmd/golangci-lint@v1.59.0 run 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

View File

@ -1,4 +1,4 @@
#!/bin/sh #!/bin/bash
# #
# Copyright 2019 The Kubernetes Authors. # Copyright 2019 The Kubernetes Authors.
# #
@ -20,7 +20,7 @@ set -o errexit
set -o nounset set -o nounset
# Ask pass some ops, fail if it mismatched the magic password. # 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. # `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. # Askpass git only support repo started with "file://" which is used in test_e2e.sh.
REPO=$(echo "$@" | grep -o "file://[^ ]*") REPO=$(echo "$@" | grep -o "file://[^ ]*")
@ -28,7 +28,7 @@ if [ "$1" = "clone" -o "$1" = "ls-remote" -o "$1" = "fetch" ]; then
USERNAME=$(echo "${OUTPUT}" | grep "^username=.*") USERNAME=$(echo "${OUTPUT}" | grep "^username=.*")
PASSWD=$(echo "${OUTPUT}" | grep "^password=.*") PASSWD=$(echo "${OUTPUT}" | grep "^password=.*")
# Test case must match the magic username and password below. # 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}" echo "invalid test username/password pair: ${USERNAME}:${PASSWD}"
exit 1 exit 1
fi fi

View File

@ -14,17 +14,18 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
if [ -z "$1" ] || [ -z "$2" ]; then
if [ -z "$1" -o -z "$2" ]; then
echo "usage: $0 <port> <shell-command>" echo "usage: $0 <port> <shell-command>"
exit 1 exit 1
fi 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 while true; do
rm -f "$F" sh -c "$2" > "$CMD_TO_NC" 2>&1 < "$NC_TO_CMD" &
mkfifo "$F" nc -l -p "$1" -N -w1 < "$CMD_TO_NC" > "$NC_TO_CMD"
cat "$F" | sh -c "$2" 2>&1 | nc -l -p "$1" -N -w1 > "$F"
date >> /var/log/hits date >> /var/log/hits
done done