Skip to content

Commit 3e88c87

Browse files
committed
Housekeeping: lint remaining scripts in bin
1 parent 0159263 commit 3e88c87

11 files changed

+861
-871
lines changed

bin/autogenerate-include.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# shellcheck disable=SC2148
12
# Copyright © 2025, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
23
# SPDX-License-Identifier: Apache-2.0
34

@@ -193,6 +194,7 @@ function checkStorageClass {
193194
log_error "Required parameter not provided. Either [$storageClassEnvVar] or [STORAGECLASS] MUST be provided."
194195
exit 1
195196
else
197+
# shellcheck disable=SC2091
196198
if $(kubectl get storageClass "$storageClass" -o name &>/dev/null); then
197199
log_debug "The specified StorageClass [$storageClass] exists"
198200
else

bin/common.sh

Lines changed: 196 additions & 189 deletions
Large diffs are not rendered by default.

bin/configure_nodeport.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Copyright ©2022, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
44
# SPDX-License-Identifier: Apache-2.0
55

6-
cd "$(dirname "$BASH_SOURCE")/.."
6+
cd "$(dirname "$BASH_SOURCE")/.." || exit
77
source logging/bin/common.sh
88

99
#TO DO: Should be done in bin/common?

bin/helm-include.sh

Lines changed: 88 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66
# This script is not intended to be run directly
77
# Assumes bin/common.sh has been sourced
88

9-
if [ ! $(which helm) ]; then
10-
echo "helm not found on the current PATH"
11-
exit 1
9+
if [ ! "$(which helm)" ]; then
10+
echo "helm not found on the current PATH"
11+
exit 1
1212
fi
1313

1414
helmVer=$(helm version --short 2>/dev/null)
15+
# shellcheck disable=SC2116,SC2086,SC2207
1516
hver=( $(echo ${helmVer//[^0-9]/ }) )
1617
HELM_VER_MAJOR=${hver[0]}
1718
HELM_VER_MINOR=${hver[1]}
@@ -25,115 +26,116 @@ if [ "$HELM_VER_MAJOR" == "2" ]; then
2526
fi
2627

2728
if [ "$V4M_HELM_USE_LATEST" == "true" ]; then
28-
log_warn "******This feature is NOT intended for use outside the project maintainers*******"
29-
log_warn "Environment variable V4M_HELM_USE_LATEST set; deploying *latest* version of all Helm charts"
29+
log_warn "******This feature is NOT intended for use outside the project maintainers*******"
30+
log_warn "Environment variable V4M_HELM_USE_LATEST set; deploying *latest* version of all Helm charts"
3031
fi
3132

3233
function helm2ReleaseExists {
33-
release=$1
34-
log_debug "Checking for Helm 2.x release of [$release]"
35-
releases=$(kubectl get configmap --all-namespaces -l "OWNER=TILLER" -o name)
36-
if [[ $releases =~ configmap/$release\.v[0-9]+ ]]; then
37-
log_debug "A Helm 2.x release of [$release] exists"
38-
return 0
39-
else
40-
return 1
41-
fi
34+
release=$1
35+
log_debug "Checking for Helm 2.x release of [$release]"
36+
releases=$(kubectl get configmap --all-namespaces -l "OWNER=TILLER" -o name)
37+
if [[ $releases =~ configmap/$release\.v[0-9]+ ]]; then
38+
log_debug "A Helm 2.x release of [$release] exists"
39+
return 0
40+
else
41+
return 1
42+
fi
4243
}
4344

4445
function helm3ReleaseExists {
45-
release=$1
46-
namespace=$2
47-
log_debug "Checking for Helm 3.x release of [$release]"
48-
releases=$(kubectl get secret -n $namespace -l name=$release,owner=helm -o name)
49-
if [[ $releases =~ secret/sh\.helm\.release\.v1\.$release\.v[0-9]+ ]]; then
50-
log_debug "A Helm 3.x release of [$release] exists"
51-
return 0
52-
else
53-
return 1
54-
fi
46+
release=$1
47+
namespace=$2
48+
log_debug "Checking for Helm 3.x release of [$release]"
49+
releases=$(kubectl get secret -n "$namespace" -l name="$release",owner=helm -o name)
50+
if [[ $releases =~ secret/sh\.helm\.release\.v1\.$release\.v[0-9]+ ]]; then
51+
log_debug "A Helm 3.x release of [$release] exists"
52+
return 0
53+
else
54+
return 1
55+
fi
5556
}
5657

5758
function helm2ReleaseCheck {
58-
if [ "$HELM_RELEASE_CHECK" != "false" ]; then
59-
release=$1
60-
if helm2ReleaseExists $release; then
61-
log_error "A Helm 2.x release of [$release] already exists"
62-
log_error "Helm [$HELM_VER_FULL] cannot manage the Helm 2.x release of [$release]"
63-
exit 1
59+
if [ "$HELM_RELEASE_CHECK" != "false" ]; then
60+
release=$1
61+
if helm2ReleaseExists "$release"; then
62+
log_error "A Helm 2.x release of [$release] already exists"
63+
log_error "Helm [$HELM_VER_FULL] cannot manage the Helm 2.x release of [$release]"
64+
exit 1
65+
fi
6466
fi
65-
fi
6667
}
6768

6869
function helmRepoAdd {
69-
repo=$1
70-
repoURL=$2
71-
72-
## If this is an air gap deployment, do nothing
73-
if [ "$AIRGAP_DEPLOYMENT" == "true" ]; then
74-
return 0
75-
fi
76-
77-
HELM_FORCE_REPO_UPDATE=${HELM_FORCE_REPO_UPDATE:-true}
78-
if [[ ! $(helm repo list 2>/dev/null) =~ $repo[[:space:]] ]]; then
79-
log_info "Adding [$repo] helm repository"
80-
helm repo add $repo $repoURL
81-
else
82-
log_debug "The helm repo [$repo] already exists"
83-
if [ "$HELM_FORCE_REPO_UPDATE" == "true" ]; then
84-
log_debug "Forcing update of [$repo] helm repo to [$repoURL]"
85-
86-
# Helm 3.3.2 changed 'repo add' behavior and added the --force-update flag
87-
# https://github.com/helm/helm/releases/tag/v3.3.2
88-
if [[ $HELM_VER_MINOR -lt 3 || ( $HELM_VER_MINOR -eq 3 && $HELM_VER_PATCH -lt 2) ]]; then
89-
helm repo add $repo $repoURL
90-
else
91-
helm repo add --force-update $repo $repoURL
92-
fi
70+
repo=$1
71+
repoURL=$2
9372

73+
## If this is an air gap deployment, do nothing
74+
if [ "$AIRGAP_DEPLOYMENT" == "true" ]; then
75+
return 0
76+
fi
77+
78+
HELM_FORCE_REPO_UPDATE=${HELM_FORCE_REPO_UPDATE:-true}
79+
# shellcheck disable=SC1087
80+
if [[ ! $(helm repo list 2>/dev/null) =~ $repo[[:space:]] ]]; then
81+
log_info "Adding [$repo] helm repository"
82+
helm repo add "$repo" "$repoURL"
83+
else
84+
log_debug "The helm repo [$repo] already exists"
85+
if [ "$HELM_FORCE_REPO_UPDATE" == "true" ]; then
86+
log_debug "Forcing update of [$repo] helm repo to [$repoURL]"
87+
88+
# Helm 3.3.2 changed 'repo add' behavior and added the --force-update flag
89+
# https://github.com/helm/helm/releases/tag/v3.3.2
90+
if [[ $HELM_VER_MINOR -lt 3 || ( $HELM_VER_MINOR -eq 3 && $HELM_VER_PATCH -lt 2) ]]; then
91+
helm repo add "$repo" "$repoURL"
92+
else
93+
helm repo add --force-update "$repo" "$repoURL"
94+
fi
95+
fi
9496
fi
95-
fi
9697
}
9798

9899
function get_helmchart_reference {
99-
local chart_repository chart_name chart_version
100-
101-
chart_repository=$1
102-
chart_name=$2
103-
chart_version=$3
104-
105-
if [ -z "$chart_repository" ]; then
106-
echo "'ERROR: Helm chart repository not specified'"
107-
return 1
108-
elif [ -z "$chart_name" ]; then
109-
echo "'ERROR: Helm chart name not specified'"
110-
return 1
111-
elif [ -z "$chart_version" ]; then
112-
echo "'ERROR: Helm chart version not specified'"
113-
return 1
114-
else
115-
#all parms have values
116-
:
117-
fi
118-
119-
if [ "$AIRGAP_HELM_FORMAT" == "tgz" ]; then
120-
echo "${AIRGAP_HELM_REPO}/${chart_name}-${chart_version}.tgz"
121-
elif [ "$AIRGAP_HELM_FORMAT" == "oci" ]; then
122-
echo "oci://${AIRGAP_HELM_REPO}/${chart_repository}/${chart_name}"
123-
else
124-
echo "${chart_repository}/${chart_name}"
125-
fi
100+
local chart_repository chart_name chart_version
101+
102+
chart_repository=$1
103+
chart_name=$2
104+
chart_version=$3
105+
106+
if [ -z "$chart_repository" ]; then
107+
echo "'ERROR: Helm chart repository not specified'"
108+
return 1
109+
elif [ -z "$chart_name" ]; then
110+
echo "'ERROR: Helm chart name not specified'"
111+
return 1
112+
elif [ -z "$chart_version" ]; then
113+
echo "'ERROR: Helm chart version not specified'"
114+
return 1
115+
else
116+
#all parms have values
117+
:
118+
fi
119+
120+
if [ "$AIRGAP_HELM_FORMAT" == "tgz" ]; then
121+
echo "${AIRGAP_HELM_REPO}/${chart_name}-${chart_version}.tgz"
122+
elif [ "$AIRGAP_HELM_FORMAT" == "oci" ]; then
123+
echo "oci://${AIRGAP_HELM_REPO}/${chart_repository}/${chart_name}"
124+
else
125+
echo "${chart_repository}/${chart_name}"
126+
fi
126127
}
127128
function get_helm_versionstring {
128129
if [ "$V4M_HELM_USE_LATEST" == "true" ]; then
129-
: # return null string
130+
: # return null string
130131
else
131-
# Explicitly use printf instead of echo to avoid quote issues
132-
printf -- "--version %s" "$1"
132+
# Explicitly use printf instead of echo to avoid quote issues
133+
printf -- "--version %s" "$1"
133134
fi
134135

135136
return
136137
}
138+
137139
export HELM_VER_FULL HELM_VER_MAJOR HELM_VER_MINOR HELM_VER_PATCH
138140
export -f helm2ReleaseExists
139141
export -f helm3ReleaseExists

bin/kube-include.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
#!/bin/bash
2-
1+
# shellcheck disable=SC2148
32
# Copyright © 2024,2020, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
43
# SPDX-License-Identifier: Apache-2.0
54

bin/log-include.sh

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# shellcheck disable=SC2148
12
# Copyright © 2021, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
23
# SPDX-License-Identifier: Apache-2.0
34

@@ -31,26 +32,30 @@ if [ "$LOG_VERBOSE_ENABLE" != "true" ]; then
3132
fi
3233

3334
function add_notice {
34-
echo $* >> $TMP_DIR/notices.txt
35+
echo "$*" >> "$TMP_DIR"/notices.txt
3536
}
3637

3738
function display_notices {
3839
if [ -f "$TMP_DIR/notices.txt" ]; then
3940
local IFS=''
40-
cat $TMP_DIR/notices.txt | while read line || [[ -n "$line" ]];
41+
cat "$TMP_DIR"/notices.txt | while read -r line || [[ -n "$line" ]];
4142
do
4243
log_notice "$line"
4344
done
4445
fi
4546
}
4647

4748
function log_notice {
49+
local msg
50+
msg=$1
4851
width=$noticeColWidth
49-
n=$(($width - $(echo "$1" | wc -c)))
52+
53+
n=$((width - ${#msg}))
5054
if [ $n -lt 0 ]; then
5155
n=0
5256
fi
5357
# Fill remaining characters with spaces
58+
# shellcheck disable=SC2046
5459
text="$*$(printf %$(eval 'echo $n')s |tr ' ' ' ')"
5560

5661
if [ "$LOG_COLOR_ENABLE" = "true" ]; then
@@ -96,7 +101,7 @@ function log_info {
96101
# The value of LOG_VERBOSE_ENABLE determines whether they are displayed
97102
function log_verbose {
98103
if [ "$LOG_VERBOSE_ENABLE" == "true" ]; then
99-
log_info $* >&3
104+
log_info "$*" >&3
100105
fi
101106
}
102107

0 commit comments

Comments
 (0)