Skip to content

Commit 04515a9

Browse files
committed
ci: add shellcheck to lint workflow and fix shellscript lints
1 parent 7695fd9 commit 04515a9

File tree

7 files changed

+46
-22
lines changed

7 files changed

+46
-22
lines changed

.github/workflows/lint.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,7 @@ jobs:
4848
id: lint
4949
if: steps.install.outcome == 'success'
5050
run: yarn lint --max-warnings=0
51+
- name: Shellcheck
52+
shell: bash
53+
run: |
54+
./scripts/shellcheck.sh

deploy/script/generate-proxying.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This script generates a client certificate and then creates a TLS secret with it
2323
for Hawtio proxying on OpenShift 4.
2424
2525
Usage:
26-
$(basename $0) [-h] [SECRET_NAME] [CN]
26+
$(basename "$0") [-h] [SECRET_NAME] [CN]
2727
2828
Options:
2929
-h Show this help
@@ -33,12 +33,13 @@ EOT
3333

3434
kube_binary() {
3535
local k
36-
k=$(command -v ${1} 2> /dev/null)
36+
k=$(command -v "${1}" 2> /dev/null)
37+
# shellcheck disable=SC2181
3738
if [ $? != 0 ]; then
3839
return
3940
fi
4041

41-
echo ${k}
42+
echo "${k}"
4243
}
4344

4445
while getopts h OPT; do
@@ -52,7 +53,7 @@ while getopts h OPT; do
5253
done
5354

5455
if [ -n "${KUBECLI}" ]; then
55-
KUBECLI=$(kube_binary ${KUBECLI})
56+
KUBECLI=$(kube_binary "${KUBECLI}")
5657
else
5758
# try finding oc
5859
KUBECLI=$(kube_binary oc)
@@ -113,10 +114,10 @@ openssl req -new -key server.key -out server.csr -config csr.conf
113114
# Issue the signed certificate
114115
openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key -CAcreateserial -out server.crt -days 10000 -extensions v3_ext -extfile csr.conf
115116

116-
if ${KUBECLI} get secret ${SECRET_NAME} -n ${NAMESPACE} 1> /dev/null 2>& 1; then
117+
if ${KUBECLI} get secret "${SECRET_NAME}" -n "${NAMESPACE}" 1> /dev/null 2>& 1; then
117118
echo "The secret ${SECRET_NAME} in ${NAMESPACE} already exists"
118119
exit 0
119120
fi
120121

121122
# Create the secret for Hawtio Online
122-
${KUBECLI} create secret tls ${SECRET_NAME} --cert server.crt --key server.key -n ${NAMESPACE}
123+
${KUBECLI} create secret tls "${SECRET_NAME}" --cert server.crt --key server.key -n "${NAMESPACE}"

deploy/script/generate-serving.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ usage() {
77
This script creates a TLS secret for Hawtio serving on Kubernetes.
88
99
Usage:
10-
$(basename $0) [-h] [-k tls_key] [-c tls_crt] [SECRET_NAME] [CN]
10+
$(basename "$0") [-h] [-k tls_key] [-c tls_crt] [SECRET_NAME] [CN]
1111
1212
Options:
1313
-c tls_key TLS key
@@ -19,12 +19,13 @@ EOT
1919

2020
kube_binary() {
2121
local k
22-
k=$(command -v ${1} 2> /dev/null)
22+
k=$(command -v "${1}" 2> /dev/null)
23+
# shellcheck disable=SC2181
2324
if [ $? != 0 ]; then
2425
return
2526
fi
2627

27-
echo ${k}
28+
echo "${k}"
2829
}
2930

3031
while getopts c:k:h OPT; do
@@ -42,7 +43,7 @@ done
4243
shift $((OPTIND - 1))
4344

4445
if [ -n "${KUBECLI}" ]; then
45-
KUBECLI=$(kube_binary ${KUBECLI})
46+
KUBECLI=$(kube_binary "${KUBECLI}")
4647
else
4748
# try finding oc
4849
KUBECLI=$(kube_binary oc)
@@ -83,10 +84,10 @@ if [ -z "${TLS_CRT}" ]; then
8384
TLS_CRT=tls.crt
8485
fi
8586

86-
if ${KUBECLI} get secret ${SECRET_NAME} -n ${NAMESPACE} 1> /dev/null 2>& 1; then
87+
if ${KUBECLI} get secret "${SECRET_NAME}" -n "${NAMESPACE}" 1> /dev/null 2>& 1; then
8788
echo "The secret ${SECRET_NAME} in ${NAMESPACE} already exists"
8889
exit 0
8990
fi
9091

9192
# Create the secret for Hawtio Online
92-
${KUBECLI} create secret tls ${SECRET_NAME} --cert tls.crt --key tls.key -n ${NAMESPACE}
93+
${KUBECLI} create secret tls "${SECRET_NAME}" --cert tls.crt --key tls.key -n "${NAMESPACE}"

docker/nginx.sh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ NGINX_HTML="/usr/share/nginx/html"
77
HAWTIO_HTML="${NGINX_HTML}/online"
88

99
# nginx.conf parameter default values
10-
export NGINX_SUBREQUEST_OUTPUT_BUFFER_SIZE=${NGINX_SUBREQUEST_OUTPUT_BUFFER_SIZE:-10m}
11-
export NGINX_CLIENT_BODY_BUFFER_SIZE=${NGINX_CLIENT_BODY_BUFFER_SIZE:-256k}
12-
export NGINX_PROXY_BUFFERS=${NGINX_PROXY_BUFFERS:-16 128k}
10+
export NGINX_SUBREQUEST_OUTPUT_BUFFER_SIZE="${NGINX_SUBREQUEST_OUTPUT_BUFFER_SIZE:-10m}"
11+
export NGINX_CLIENT_BODY_BUFFER_SIZE="${NGINX_CLIENT_BODY_BUFFER_SIZE:-256k}"
12+
export NGINX_PROXY_BUFFERS="${NGINX_PROXY_BUFFERS:-16 128k}"
1313

1414
export OPENSHIFT=true
1515

@@ -19,11 +19,11 @@ check_openshift_api() {
1919
TOKEN=$(cat ${SERVICEACCOUNT}/token)
2020
CACERT=${SERVICEACCOUNT}/ca.crt
2121

22-
STATUS_CODE=$(curl --cacert ${CACERT} --header "Authorization: Bearer ${TOKEN}" -X GET ${APISERVER}/apis/apps.openshift.io/v1 --write-out '%{http_code}' --silent --output /dev/null)
22+
STATUS_CODE=$(curl --cacert ${CACERT} --header "Authorization: Bearer ${TOKEN}" -X GET "${APISERVER}"/apis/apps.openshift.io/v1 --write-out '%{http_code}' --silent --output /dev/null)
2323
if [ "${STATUS_CODE}" != "200" ]; then
2424
OPENSHIFT=false
2525
fi
26-
echo OpenShift API: ${OPENSHIFT} - ${STATUS_CODE} ${APISERVER}/apis/apps.openshift.io/v1
26+
echo "OpenShift API: ${OPENSHIFT} - ${STATUS_CODE} ${APISERVER}/apis/apps.openshift.io/v1"
2727
}
2828

2929
check_openshift_api
@@ -40,6 +40,7 @@ generate_nginx_gateway_conf() {
4040
if [ "${OPENSHIFT}" = "false" ]; then
4141
TEMPLATE=/nginx-gateway-k8s.conf.template
4242
fi
43+
# shellcheck disable=SC2016
4344
envsubst '
4445
$NGINX_SUBREQUEST_OUTPUT_BUFFER_SIZE
4546
$NGINX_CLIENT_BODY_BUFFER_SIZE
@@ -58,6 +59,7 @@ else
5859
ln -sf /nginx.conf /etc/nginx/conf.d/nginx.conf
5960
fi
6061

62+
# shellcheck disable=SC2181
6163
if [ $? = 0 ]; then
6264
echo Starting NGINX...
6365
nginx -g 'daemon off;'

docker/osconsole/config.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ invalid() {
103103
exit 1
104104
}
105105

106-
if [ "${OPENSHIFT}" == "true" ]; then
106+
if [ "${OPENSHIFT}" = "true" ]; then
107107
MASTER_KIND=openshift
108108
else
109109
MASTER_KIND=kubernetes

scripts/disable-jolokia-auth.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#!/bin/bash
22

33
# target dc labeled 'provider=fabric8'
4-
if [ -z $1 ]; then
4+
if [ -z "$1" ]; then
55
names=$(oc get dc --selector='provider=fabric8' -o 'jsonpath={.items[*].metadata.name}')
66
else
77
names=$1
88
fi
99

10-
if [ -z $names ]; then
10+
if [ -z "$names" ]; then
1111
echo "No deployment configs are selected."
1212
exit 1
1313
fi
1414

15-
echo $names | tr " " "\n"
15+
echo "$names" | tr " " "\n"
1616
read -p "Disable Jolokia authentication & SSL for these deployment configs? [y/N]: " -r yn
1717
if [ "$yn" != "y" ]; then
1818
exit 0
@@ -22,7 +22,7 @@ for name in $names; do
2222
echo "Disabling: $name"
2323

2424
echo " oc set env dc/$name AB_JOLOKIA_AUTH_OPENSHIFT=false AB_JOLOKIA_PASSWORD_RANDOM=false AB_JOLOKIA_OPTS=useSslClientAuthentication=false,protocol=https"
25-
oc set env dc/$name \
25+
oc set env dc/"$name" \
2626
AB_JOLOKIA_AUTH_OPENSHIFT=false \
2727
AB_JOLOKIA_PASSWORD_RANDOM=false \
2828
AB_JOLOKIA_OPTS=useSslClientAuthentication=false,protocol=https

scripts/shellcheck.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env bash
2+
3+
excludes=""
4+
5+
target_dirs=(
6+
"scripts"
7+
"deploy/openshift/cluster"
8+
"deploy/script"
9+
"docker"
10+
"docker/osconsole"
11+
)
12+
13+
for dir in "${target_dirs[@]}"; do
14+
echo Linting "$dir/*.sh"
15+
shellcheck "$dir"/*.sh -e "$excludes"
16+
done

0 commit comments

Comments
 (0)