Skip to content

Commit c9ce361

Browse files
committed
Linting (shellck)
1 parent e5bef8e commit c9ce361

13 files changed

+624
-635
lines changed

bin/airgap-include.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# This file is not marked as executable as it is intended to be sourced
66
# Current directory must be the root directory of the repo
77

8-
98
if [ "$AIRGAP_SOURCED" == "" ]; then
109
## Check for AIRGAP_REGISTRY, if null/empty, error out. Otherwise set and create HELM_URL_BASE.
1110
if [ -z "$AIRGAP_REGISTRY" ]; then

bin/autogenerate-include.sh

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
# This file is not marked as executable as it is intended to be sourced
66
# Current directory must be the root directory of the repo
77

8-
98
function checkYqVersion {
109
# confirm yq installed and correct version
1110
local goodver yq_version
@@ -36,8 +35,8 @@ function create_ingress_certs {
3635
if [ -f "$certFile" ] && [ -f "$keyFile" ]; then
3736
kubectl delete secret "$secretName" --namespace "$namespace" --ignore-not-found
3837
kubectl create secret tls "$secretName" --namespace "$namespace" --key="$keyFile" --cert="$certFile"
39-
kubectl -n "$namespace" label secret "$secretName" managed-by="v4m-es-script"
40-
elif [ -n "$certFile$keyFile" ]; then
38+
kubectl -n "$namespace" label secret "$secretName" managed-by="v4m-es-script"
39+
elif [ -n "$certFile$keyFile" ]; then
4140
log_warn "Missing Ingress certificate file; specified Ingress cert [$certFile] and/or key [$keyFile] file is missing."
4241
log_warn "Create the missing Kubernetes secrets after deployment; use command: kubectl -create secret tls $secretName --namespace $namespace --key=cert_key_file --cert=cert_file"
4342
fi
@@ -162,7 +161,7 @@ if [ -z "$AUTOGENERATE_SOURCED" ]; then
162161
log_debug "Secret [$SMTP_USER_SECRET] exists; will use it for SMTP user credentials"
163162
elif [ -z "$SMTP_USER" ] && [ -z "$SMTP_PASSWORD" ]; then
164163
log_debug "Neither SMTP_USER nor SMTP_PASSWORD are set; skipping creation of secret [$SMTP_USER_SECRET]"
165-
elif [ -z "$SMTP_USER" ] || [ -z "$SMTP_PASSWORD" ]; then
164+
elif [ -z "$SMTP_USER" ] || [ -z "$SMTP_PASSWORD" ]; then
166165
log_error "Complete SMTP Credentials NOT provided; MUST provide BOTH [SMTP_USER] and [SMTP_PASSWORD]"
167166
log_info "SMTP_USER is set to [$SMTP_USER] and SMTP_PASSWORD is set to [$SMTP_PASSWORD]"
168167
exit 1
@@ -176,13 +175,12 @@ if [ -z "$AUTOGENERATE_SOURCED" ]; then
176175

177176
export AUTOGENERATE_SOURCED="true"
178177

179-
elif [ "$AUTOGENERATE_SOURCED" == "NotNeeded" ]; then
180-
log_debug "autogenerate-include.sh not needed"
181-
else
182-
log_debug "autogenerate-include.sh was already sourced [$AUTOGENERATE_SOURCED]"
178+
elif [ "$AUTOGENERATE_SOURCED" == "NotNeeded" ]; then
179+
log_debug "autogenerate-include.sh not needed"
180+
else
181+
log_debug "autogenerate-include.sh was already sourced [$AUTOGENERATE_SOURCED]"
183182
fi
184183

185-
186184
function checkStorageClass {
187185
# input parms: $1 *Name of env var* identifying storageClass
188186
# input parms: $2 storageClass
@@ -197,7 +195,7 @@ function checkStorageClass {
197195
exit 1
198196
else
199197
# shellcheck disable=SC2091
200-
if $(kubectl get storageClass "$storageClass" -o name &>/dev/null); then
198+
if $(kubectl get storageClass "$storageClass" -o name &> /dev/null); then
201199
log_debug "The specified StorageClass [$storageClass] exists"
202200
else
203201
log_error "The specified StorageClass [$storageClass] does NOT exist"

bin/colors-include.sh

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,67 +35,67 @@ lightbluebg="\033[46m"
3535

3636
# Foregrounds
3737
function black {
38-
echo -e "${black}${1}${end}" >&3
38+
echo -e "${black}${1}${end}" >&3
3939
}
4040

4141
function blackb {
42-
echo -e "${blackb}${1}${end}" >&3
42+
echo -e "${blackb}${1}${end}" >&3
4343
}
4444

4545
function white {
46-
echo -e "${white}${1}${end}" >&3
46+
echo -e "${white}${1}${end}" >&3
4747
}
4848

4949
function whiteb {
50-
echo -e "${whiteb}${1}${end}" >&3
50+
echo -e "${whiteb}${1}${end}" >&3
5151
}
5252

5353
function red {
54-
echo -e "${red}${1}${end}" >&3
54+
echo -e "${red}${1}${end}" >&3
5555
}
5656

5757
function redb {
58-
echo -e "${redb}${1}${end}" >&3
58+
echo -e "${redb}${1}${end}" >&3
5959
}
6060

6161
function green {
62-
echo -e "${green}${1}${end}" >&3
62+
echo -e "${green}${1}${end}" >&3
6363
}
6464

6565
function greenb {
66-
echo -e "${greenb}${1}${end}" >&3
66+
echo -e "${greenb}${1}${end}" >&3
6767
}
6868

6969
function yellow {
70-
echo -e "${yellow}${1}${end}" >&3
70+
echo -e "${yellow}${1}${end}" >&3
7171
}
7272

7373
function yellowb {
74-
echo -e "${yellowb}${1}${end}" >&3
74+
echo -e "${yellowb}${1}${end}" >&3
7575
}
7676

7777
function blue {
78-
echo -e "${blue}${1}${end}" >&3
78+
echo -e "${blue}${1}${end}" >&3
7979
}
8080

8181
function blueb {
82-
echo -e "${blueb}${1}${end}" >&3
82+
echo -e "${blueb}${1}${end}" >&3
8383
}
8484

8585
function purple {
86-
echo -e "${purple}${1}${end}" >&3
86+
echo -e "${purple}${1}${end}" >&3
8787
}
8888

8989
function purpleb {
90-
echo -e "${purpleb}${1}${end}" >&3
90+
echo -e "${purpleb}${1}${end}" >&3
9191
}
9292

9393
function lightblue {
94-
echo -e "${lightblue}${1}${end}" >&3
94+
echo -e "${lightblue}${1}${end}" >&3
9595
}
9696

9797
function lightblueb {
98-
echo -e "${lightblueb}${1}${end}" >&3
98+
echo -e "${lightblueb}${1}${end}" >&3
9999
}
100100

101101
# Export all the things

bin/common.sh

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,25 @@
66
# Current directory must be the root directory of the repo
77

88
function trap_add() {
9-
# based on https://stackoverflow.com/questions/3338030/multiple-bash-traps-for-the-same-signal
10-
# but: prepends new cmd rather than append it, changed var names and eliminated messages
11-
12-
local cmd_to_add signal
13-
14-
cmd_to_add=$1; shift
15-
for signal in "$@"; do
16-
trap -- "$(
17-
# print the new trap command
18-
printf '%s\n' "${cmd_to_add}"
19-
# helper fn to get existing trap command from output
20-
# of trap -p
21-
# shellcheck disable=SC2329,SC2317
22-
extract_trap_cmd() { printf '%s\n' "$3"; }
23-
# print existing trap command with newline
24-
eval "extract_trap_cmd $(trap -p "${signal}")"
25-
)" "${signal}"
26-
done
9+
# based on https://stackoverflow.com/questions/3338030/multiple-bash-traps-for-the-same-signal
10+
# but: prepends new cmd rather than append it, changed var names and eliminated messages
11+
12+
local cmd_to_add signal
13+
14+
cmd_to_add=$1
15+
shift
16+
for signal in "$@"; do
17+
trap -- "$(
18+
# print the new trap command
19+
printf '%s\n' "${cmd_to_add}"
20+
# helper fn to get existing trap command from output
21+
# of trap -p
22+
# shellcheck disable=SC2329,SC2317
23+
extract_trap_cmd() { printf '%s\n' "$3"; }
24+
# print existing trap command with newline
25+
eval "extract_trap_cmd $(trap -p "${signal}")"
26+
)" "${signal}"
27+
done
2728
}
2829

2930
function errexit_msg {
@@ -72,7 +73,10 @@ if [ "$SAS_COMMON_SOURCED" = "" ]; then
7273
export USER_DIR=${USER_DIR:-$(pwd)}
7374
if [ -d "$USER_DIR" ]; then
7475
# Resolve full path
75-
USER_DIR=$(cd "$(dirname "$USER_DIR")" || exit; pwd)/$(basename "$USER_DIR")
76+
USER_DIR=$(
77+
cd "$(dirname "$USER_DIR")" || exit
78+
pwd
79+
)/$(basename "$USER_DIR")
7680
export USER_DIR
7781
fi
7882
if [ -f "$USER_DIR/user.env" ]; then
@@ -122,7 +126,6 @@ if [ "$SAS_COMMON_SOURCED" = "" ]; then
122126
# set TLS Cert Generator (cert-manager|openssl)
123127
export CERT_GENERATOR="${CERT_GENERATOR:-openssl}"
124128

125-
126129
# Set default timeout for kubectl namespace delete command
127130
export KUBE_NAMESPACE_DELETE_TIMEOUT=${KUBE_NAMESPACE_DELETE_TIMEOUT:-5m}
128131

@@ -154,7 +157,7 @@ fi
154157

155158
function checkDefaultStorageClass {
156159
if [ -z "$defaultStorageClass" ]; then
157-
# Check for kubernetes environment conflicts/requirements
160+
# Check for kubernetes environment conflicts/requirements
158161
defaultStorageClass=$(kubectl get storageclass -o jsonpath="{range .items[*]}{.metadata.name}{'\t'}{.metadata.annotations..storageclass\.kubernetes\.io/is-default-class}{'\n'}{end}" | grep true | awk '{print $1}')
159162
if [ "$defaultStorageClass" ]; then
160163
log_debug "Found default storageClass: [$defaultStorageClass]"
@@ -198,21 +201,20 @@ function validateTenantID {
198201
fi
199202
}
200203

201-
202204
function validateNamespace {
203205
local namespace
204206
namespace="$1"
205-
if [[ "$namespace" =~ ^[a-z0-9]([\-a-z0-9]*[a-z0-9])?$ ]]; then
207+
if [[ $namespace =~ ^[a-z0-9]([\-a-z0-9]*[a-z0-9])?$ ]]; then
206208
log_debug "Namespace [$namespace] passes validation"
207209
else
208210
log_error "[$namespace] is not a valid namespace name"
209211
exit 1
210212
fi
211213
}
212214

213-
214215
function randomPassword {
215-
date +%s | sha256sum | base64 | head -c 32 ; echo
216+
date +%s | sha256sum | base64 | head -c 32
217+
echo
216218
}
217219

218220
function disable_sa_token_automount {
@@ -222,7 +224,7 @@ function disable_sa_token_automount {
222224
should_disable=${SEC_DISABLE_SA_TOKEN_AUTOMOUNT:-true}
223225

224226
if [ "$should_disable" == "true" ]; then
225-
if [ -n "$(kubectl -n "$ns" get serviceAccount "$sa_name" -o name 2>/dev/null)" ]; then
227+
if [ -n "$(kubectl -n "$ns" get serviceAccount "$sa_name" -o name 2> /dev/null)" ]; then
226228
log_debug "Disabling automount of API tokens for serviceAccount [$ns/$sa_name]"
227229
kubectl -n "$ns" patch serviceAccount "$sa_name" -p '{"automountServiceAccountToken":false}'
228230
else
@@ -244,7 +246,7 @@ function enable_pod_token_automount {
244246
log_debug "Enabling automount of API tokens for pods deployed via [$resource_type/$resource_name]"
245247

246248
if [ "$resource_type" == "daemonset" ] || [ "$resource_type" == "deployment" ]; then
247-
kubectl -n "$ns" patch "$resource_type" "$resource_name" -p '{"spec": {"template": {"spec": {"automountServiceAccountToken":true}}}}'
249+
kubectl -n "$ns" patch "$resource_type" "$resource_name" -p '{"spec": {"template": {"spec": {"automountServiceAccountToken":true}}}}'
248250
else
249251
log_error "Invalid request to function [${FUNCNAME[0]}]; unsupported resource_type [$resource_type]"
250252
return 1
@@ -264,31 +266,30 @@ export -f disable_sa_token_automount
264266
export -f enable_pod_token_automount
265267

266268
function parseFullImage {
267-
# shellcheck disable=SC2034
268-
fullImage="$1"
269-
unset REGISTRY REPOS IMAGE VERSION FULL_IMAGE_ESCAPED
269+
# shellcheck disable=SC2034
270+
fullImage="$1"
271+
unset REGISTRY REPOS IMAGE VERSION FULL_IMAGE_ESCAPED
270272

271-
if [[ "$1" =~ (.*)\/(.*)\/(.*)\:(.*) ]]; then
273+
if [[ $1 =~ (.*)\/(.*)\/(.*)\:(.*) ]]; then
272274
REGISTRY="${BASH_REMATCH[1]}"
273275
REPOS="${BASH_REMATCH[2]}"
274276
IMAGE="${BASH_REMATCH[3]}"
275277
VERSION="${BASH_REMATCH[4]}"
276278
# shellcheck disable=SC2034
277279
FULL_IMAGE_ESCAPED="$REGISTRY\/$REPOS\/$IMAGE\:$VERSION"
278280
return 0
279-
else
281+
else
280282
log_warn "Invalid value for full container image; does not fit expected pattern [$1]."
281283
return 1
282-
fi
284+
fi
283285
}
284286

285-
286287
function v4m_replace {
287288

288289
if echo "$OSTYPE" | grep 'darwin' > /dev/null 2>&1; then
289-
sed -i '' "s;$1;$2;g" "$3"
290+
sed -i '' "s;$1;$2;g" "$3"
290291
else
291-
sed -i "s;$1;$2;g" "$3"
292+
sed -i "s;$1;$2;g" "$3"
292293
fi
293294
}
294295

@@ -304,7 +305,7 @@ function generateImageKeysFile {
304305

305306
local pullsecret_text
306307

307-
if ! parseFullImage "$1"; then
308+
if ! parseFullImage "$1"; then
308309
log_error "Unable to parse full image [$1]"
309310
return 1
310311
fi
@@ -316,8 +317,8 @@ function generateImageKeysFile {
316317
template_file=$2
317318

318319
if [ "$template_file" != "$imageKeysFile" ]; then
319-
rm -f "$imageKeysFile"
320-
cp "$template_file" "$imageKeysFile"
320+
rm -f "$imageKeysFile"
321+
cp "$template_file" "$imageKeysFile"
321322
else
322323
log_debug "Modifying an existing imageKeysFile"
323324
fi
@@ -349,20 +350,19 @@ function generateImageKeysFile {
349350
v4m_pullPolicy=${V4M_PULL_POLICY:-"IfNotPresent"}
350351

351352
v4m_replace "__${prefix}GLOBAL_REGISTRY_OSBUG__" "$GLOBAL_REGISTRY_OSBUG" "$imageKeysFile"
352-
v4m_replace "__${prefix}GLOBAL_REGISTRY__" "$GLOBAL_REGISTRY" "$imageKeysFile"
353+
v4m_replace "__${prefix}GLOBAL_REGISTRY__" "$GLOBAL_REGISTRY" "$imageKeysFile"
353354
v4m_replace "__${prefix}IMAGE_REGISTRY__" "$REGISTRY" "$imageKeysFile"
354-
v4m_replace "__${prefix}IMAGE_REPO_3LEVEL__" "$REGISTRY\/$REPOS\/$IMAGE" "$imageKeysFile"
355-
v4m_replace "__${prefix}IMAGE_REPO_2LEVEL__" "$REPOS\/$IMAGE" "$imageKeysFile"
356-
v4m_replace "__${prefix}IMAGE__" "$IMAGE" "$imageKeysFile"
357-
v4m_replace "__${prefix}IMAGE_TAG__" "$VERSION" "$imageKeysFile"
358-
v4m_replace "__${prefix}IMAGE_PULL_POLICY__" "$v4m_pullPolicy" "$imageKeysFile"
359-
v4m_replace "__${prefix}IMAGE_PULL_SECRET__" "$pullsecret_text" "$imageKeysFile" #Handle Charts Accepting a Single Image Pull Secret
360-
v4m_replace "__${prefix}IMAGE_PULL_SECRETS__" "$pullsecrets_text" "$imageKeysFile" #Handle Charts Accepting Multiple Image Pull Secrets
355+
v4m_replace "__${prefix}IMAGE_REPO_3LEVEL__" "$REGISTRY\/$REPOS\/$IMAGE" "$imageKeysFile"
356+
v4m_replace "__${prefix}IMAGE_REPO_2LEVEL__" "$REPOS\/$IMAGE" "$imageKeysFile"
357+
v4m_replace "__${prefix}IMAGE__" "$IMAGE" "$imageKeysFile"
358+
v4m_replace "__${prefix}IMAGE_TAG__" "$VERSION" "$imageKeysFile"
359+
v4m_replace "__${prefix}IMAGE_PULL_POLICY__" "$v4m_pullPolicy" "$imageKeysFile"
360+
v4m_replace "__${prefix}IMAGE_PULL_SECRET__" "$pullsecret_text" "$imageKeysFile" #Handle Charts Accepting a Single Image Pull Secret
361+
v4m_replace "__${prefix}IMAGE_PULL_SECRETS__" "$pullsecrets_text" "$imageKeysFile" #Handle Charts Accepting Multiple Image Pull Secrets
361362

362363
return 0
363364
}
364365

365-
366366
export -f parseFullImage
367367
export -f v4m_replace
368368
export -f generateImageKeysFile

0 commit comments

Comments
 (0)