Skip to content

Commit 3714242

Browse files
committed
Housekeeping: lint remaining scripts in logging/bin
1 parent e4a36d1 commit 3714242

10 files changed

+125
-115
lines changed

logging/bin/deploy_logging_azmonitor.sh

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,16 @@
33
# Copyright © 2020, 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 1
77
source logging/bin/common.sh
88

99
# temp file used to capture command output
10+
# shellcheck disable=SC2034
1011
tmpfile=$TMP_DIR/output.txt
1112
rm -f tmpfile
1213

13-
if [ "$(kubectl get ns $LOG_NS -o name 2>/dev/null)" == "" ]; then
14-
kubectl create ns $LOG_NS
14+
if [ "$(kubectl get ns "$LOG_NS" -o name 2>/dev/null)" == "" ]; then
15+
kubectl create ns "$LOG_NS"
1516
fi
1617

1718
set -e

logging/bin/deploy_servicemonitors_openshift.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# Copyright © 2021, 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

9-
this_script=`basename "$0"`
9+
this_script=$(basename "$0")
1010

1111
log_debug "Script [$this_script] has started [$(date)]"
1212

@@ -21,19 +21,19 @@ fi
2121
EVENTROUTER_ENABLE=${EVENTROUTER_ENABLE:-true}
2222
if [ "$EVENTROUTER_ENABLE" == "true" ]; then
2323
# Eventrouter ServiceMonitor
24-
kubectl apply -n $LOG_NS -f monitoring/monitors/kube/podMonitor-eventrouter.yaml
24+
kubectl apply -n "$LOG_NS" -f monitoring/monitors/kube/podMonitor-eventrouter.yaml
2525
fi
2626

2727
ELASTICSEARCH_ENABLE=${ELASTICSEARCH_ENABLE:-true}
2828
if [ "$ELASTICSEARCH_ENABLE" == "true" ]; then
2929
# Elasticsearch ServiceMonitor
30-
kubectl apply -n $LOG_NS -f monitoring/monitors/logging/serviceMonitor-elasticsearch.yaml
30+
kubectl apply -n "$LOG_NS" -f monitoring/monitors/logging/serviceMonitor-elasticsearch.yaml
3131
fi
3232

3333
FLUENT_BIT_ENABLED=${FLUENT_BIT_ENABLED:-true}
3434
if [ "$FLUENT_BIT_ENABLED" == "true" ]; then
3535
# Fluent Bit ServiceMonitors
36-
kubectl apply -n $LOG_NS -f monitoring/monitors/logging/serviceMonitor-fluent-bit-v2.yaml
36+
kubectl apply -n "$LOG_NS" -f monitoring/monitors/logging/serviceMonitor-fluent-bit-v2.yaml
3737
fi
3838

3939
log_info "ServiceMonitors have been deployed."

logging/bin/offboard.sh

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
# Copyright © 2021, 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
source logging/bin/apiaccess-include.sh
1010
source logging/bin/secrets-include.sh
1111
source logging/bin/rbac-include.sh
1212

13-
this_script=`basename "$0"`
13+
this_script=$(basename "$0")
1414

1515

1616
function show_usage {
@@ -40,7 +40,7 @@ POS_PARMS=""
4040
while (( "$#" )); do
4141
case "$1" in
4242
-ns|--namespace)
43-
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
43+
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
4444
namespace=$2
4545
shift 2
4646
else
@@ -50,7 +50,7 @@ while (( "$#" )); do
5050
fi
5151
;;
5252
-t|--tenant)
53-
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
53+
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
5454
tenant=$2
5555
shift 2
5656
else
@@ -63,7 +63,7 @@ while (( "$#" )); do
6363
show_usage
6464
exit
6565
;;
66-
-*|--*=) # unsupported flags
66+
--*=|-*) # unsupported flags
6767
log_error "Unsupported flag $1" >&2
6868
show_usage
6969
exit 1
@@ -96,15 +96,16 @@ if [ "$namespace" == "global" ]; then
9696
exit 1
9797
fi
9898

99-
validateNamespace $namespace
99+
validateNamespace "$namespace"
100100

101101
if [ -n "$tenant" ]; then
102-
validateTenantID $tenant
102+
validateTenantID "$tenant"
103103

104104
nst="${namespace}_${tenant}"
105105
index_nst="${namespace}-__${tenant}__"
106106
else
107107
nst="$namespace"
108+
# shellcheck disable=SC2034
108109
index_nst="${namespace}"
109110
fi
110111

@@ -115,6 +116,7 @@ if [ -n "$tenant" ]; then
115116
tenant_description="An OpenSearch Dashboards tenant space for tenant [$tenant] within SAS Viya deployment (namespace) [$namespace]."
116117
log_notice "Offboarding tenant [$tenant] within namespace [$namespace] [$(date)]"
117118
else
119+
# shellcheck disable=SC2034
118120
tenant_description="An OpenSearch Dashboards tenant space for SAS Viya deployment (namespace) [$namespace]."
119121
log_notice "Offboarding namespace [$namespace] [$(date)]"
120122
fi
@@ -150,14 +152,14 @@ fi
150152

151153
# Delete ES index containing tenant content
152154
kibana_index_name=".kibana_*_$(echo "$ktenant"|tr -d _)"
153-
response=$(curl -s -o /dev/null -w "%{http_code}" -XDELETE "${es_api_url}/$kibana_index_name" --user $ES_ADMIN_USER:$ES_ADMIN_PASSWD --insecure)
155+
response=$(curl -s -o /dev/null -w "%{http_code}" -XDELETE "${es_api_url}/$kibana_index_name" --user "$ES_ADMIN_USER":"$ES_ADMIN_PASSWD" --insecure)
154156
if [[ $response == 2* ]]; then
155157
log_info "Deleted index [$kibana_index_name]. [$response]"
156158
else
157159
log_warn "There was an issue deleting the index [$kibana_index_name] holding content related to OpenSearch Dashboards tenant space [$ktenant]. You may need to manually delete this index. [$response]"
158160
fi
159161

160-
response=$(curl -s -o /dev/null -w "%{http_code}" -XDELETE "${es_api_url}/${kibana_index_name}_*" --user $ES_ADMIN_USER:$ES_ADMIN_PASSWD --insecure)
162+
response=$(curl -s -o /dev/null -w "%{http_code}" -XDELETE "${es_api_url}/${kibana_index_name}_*" --user "$ES_ADMIN_USER":"$ES_ADMIN_PASSWD" --insecure)
161163
if [[ $response == 2* ]]; then
162164
log_info "Deleted index [${kibana_index_name}_*]. [$response]"
163165
else
@@ -166,13 +168,13 @@ fi
166168

167169

168170
# Delete access controls
169-
./logging/bin/security_delete_rbac.sh $namespace $tenant
171+
./logging/bin/security_delete_rbac.sh "$namespace" "$tenant"
170172

171173
# Delete Grafana Datasource utility user (if exists)
172174
grfds_user="${nst}_grafana_ds"
173-
if user_exists $grfds_user; then
175+
if user_exists "$grfds_user"; then
174176
log_verbose "Removing the [$grfds_user] utility account."
175-
delete_user $grfds_user
177+
delete_user "$grfds_user"
176178
fi
177179

178180
# Reminder that users are not deleted

logging/bin/onboard.sh

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

3-
# Copyright © 2021, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
3+
# Copyright © 2021, 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
source logging/bin/apiaccess-include.sh
1010
source logging/bin/secrets-include.sh
1111
source logging/bin/rbac-include.sh
1212

13-
this_script=`basename "$0"`
13+
this_script=$(basename "$0")
1414

1515

1616
function show_usage {
@@ -44,7 +44,7 @@ POS_PARMS=""
4444
while (( "$#" )); do
4545
case "$1" in
4646
-ns|--namespace)
47-
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
47+
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
4848
namespace=$2
4949
shift 2
5050
else
@@ -54,7 +54,7 @@ while (( "$#" )); do
5454
fi
5555
;;
5656
-t|--tenant)
57-
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
57+
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
5858
tenant=$2
5959
shift 2
6060
else
@@ -64,7 +64,7 @@ while (( "$#" )); do
6464
fi
6565
;;
6666
-u|--user)
67-
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
67+
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
6868
createuser=true
6969
inituser=$2
7070
shift 2
@@ -75,7 +75,7 @@ while (( "$#" )); do
7575
fi
7676
;;
7777
-p|--password)
78-
if [ -n "$2" ] && [ ${2:0:1} != "-" ]; then
78+
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]; then
7979
initpasswd=$2
8080
shift 2
8181
else
@@ -124,12 +124,13 @@ fi
124124
validateNamespace "$namespace"
125125

126126
if [ -n "$tenant" ]; then
127-
validateTenantID $tenant
127+
validateTenantID "$tenant"
128128

129129
nst="${namespace}_${tenant}"
130130
index_nst="${namespace}-__${tenant}__"
131131
else
132132
nst="$namespace"
133+
# shellcheck disable=SC2034
133134
index_nst="${namespace}"
134135
fi
135136

@@ -175,29 +176,29 @@ fi
175176
get_kb_api_url
176177

177178
# Import appropriate content into OpenSearch Dashboards tenant space
178-
./logging/bin/import_osd_content.sh logging/osd/common $ktenant
179+
./logging/bin/import_osd_content.sh logging/osd/common "$ktenant"
179180

180181
if [ -z "$tenant" ]; then
181-
./logging/bin/import_osd_content.sh logging/osd/namespace $ktenant
182+
./logging/bin/import_osd_content.sh logging/osd/namespace "$ktenant"
182183
else
183-
./logging/bin/import_osd_content.sh logging/osd/tenant $ktenant
184+
./logging/bin/import_osd_content.sh logging/osd/tenant "$ktenant"
184185
fi
185186

186187
if [ -d "$USER_DIR/logging/osd" ] && [ "$USER_DIR" != "$(pwd)" ]; then
187188

188189
export IGNORE_NOT_FOUND="true"
189-
./logging/bin/import_osd_content.sh $USER_DIR/logging/osd/common $ktenant
190+
./logging/bin/import_osd_content.sh "$USER_DIR"/logging/osd/common "$ktenant"
190191

191192
if [ -z "$tenant" ]; then
192-
./logging/bin/import_osd_content.sh $USER_DIR/logging/osd/namespace $ktenant
193+
./logging/bin/import_osd_content.sh "$USER_DIR"/logging/osd/namespace "$ktenant"
193194
else
194-
./logging/bin/import_osd_content.sh $USER_DIR/logging/osd/tenant $ktenant
195+
./logging/bin/import_osd_content.sh "$USER_DIR"/logging/osd/tenant "$ktenant"
195196
fi
196197
unset IGNORE_NOT_FOUND
197198
fi
198199

199200
# Create access controls
200-
./logging/bin/security_create_rbac.sh $namespace $tenant
201+
./logging/bin/security_create_rbac.sh "$namespace" "$tenant"
201202

202203
# Create an initial user
203204
if [ "$createuser" == "true" ]; then
@@ -215,15 +216,15 @@ if [ "$createuser" == "true" ]; then
215216
passwdarg=""
216217
fi
217218

218-
if user_exists $inituser; then
219+
if user_exists "$inituser"; then
219220
log_warn "A user with the requested user name of [$inituser] already exists; the initial user account you requested was NOT created."
220221
log_warn "This existing user may have completely different access controls than you intended for the initial user."
221222
log_warn "You can create a new user with the appropriate access controls by calling the logging/bin/user.sh script directly."
222223
else
223224
if [ -z "$tenant" ]; then
224-
./logging/bin/user.sh CREATE -ns $namespace -u $inituser $passwdarg
225+
./logging/bin/user.sh CREATE -ns "$namespace" -u "$inituser" "$passwdarg"
225226
else
226-
./logging/bin/user.sh CREATE -ns $namespace -t $tenant -u $inituser $passwdarg
227+
./logging/bin/user.sh CREATE -ns "$namespace" -t "$tenant" -u "$inituser" "$passwdarg"
227228
fi
228229
fi
229230
else

logging/bin/remove_eventrouter.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
# Copyright © 2020, 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

9-
this_script=`basename "$0"`
9+
this_script=$(basename "$0")
1010

1111
log_debug "Script [$this_script] has started [$(date)]"
1212

1313
# Copy template files to temp
1414
logDir=$TMP_DIR/$LOG_NS
15-
mkdir -p $logDir
16-
cp -R logging/eventrouter/eventrouter.yaml $logDir/eventrouter.yaml
15+
mkdir -p "$logDir"
16+
cp -R logging/eventrouter/eventrouter.yaml "$logDir"/eventrouter.yaml
1717

1818
# Replace placeholders
1919
log_debug "Replacing logging namespace for files in [$logDir]"
2020
if echo "$OSTYPE" | grep 'darwin' > /dev/null 2>&1; then
21-
sed -i '' "s/__LOG_NS__/$LOG_NS/g" $logDir/eventrouter.yaml
21+
sed -i '' "s/__LOG_NS__/$LOG_NS/g" "$logDir"/eventrouter.yaml
2222
else
23-
sed -i "s/__LOG_NS__/$LOG_NS/g" $logDir/eventrouter.yaml
23+
sed -i "s/__LOG_NS__/$LOG_NS/g" "$logDir"/eventrouter.yaml
2424
fi
2525

2626
log_info "Removing Event Router [$(date)]"
@@ -30,7 +30,7 @@ if [[ $V4M_CURRENT_VERSION_FULL =~ 1.0 || $V4M_CURRENT_VERSION_FULL =~ 1.1.[0-2]
3030
log_info "Removing instance of Event Router in the kube-system namespace"
3131
kubectl delete --ignore-not-found -f logging/eventrouter/eventrouter_kubesystem.yaml
3232
else
33-
kubectl delete --ignore-not-found -f $logDir/eventrouter.yaml
33+
kubectl delete --ignore-not-found -f "$logDir"/eventrouter.yaml
3434
fi
3535

3636
log_debug "Script [$this_script] has completed [$(date)]"

logging/bin/remove_logging_azmonitor.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Copyright © 2020, 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
LOG_DELETE_NAMESPACE_ON_REMOVE=${LOG_DELETE_NAMESPACE_ON_REMOVE:-false}
@@ -18,7 +18,7 @@ logging/bin/remove_eventrouter.sh
1818

1919
if [ "$LOG_DELETE_NAMESPACE_ON_REMOVE" == "true" ]; then
2020
log_info "Deleting the [$LOG_NS] namespace..."
21-
if kubectl delete namespace $LOG_NS --timeout $KUBE_NAMESPACE_DELETE_TIMEOUT; then
21+
if kubectl delete namespace "$LOG_NS" --timeout "$KUBE_NAMESPACE_DELETE_TIMEOUT"; then
2222
log_info "[$LOG_NS] namespace and logging components successfully removed"
2323
exit 0
2424
else
@@ -37,7 +37,7 @@ crds=( secrets all )
3737
empty="true"
3838
for crd in "${crds[@]}"
3939
do
40-
out=$(kubectl get -n $LOG_NS $crd 2>&1)
40+
out=$(kubectl get -n "$LOG_NS" "$crd" 2>&1)
4141
if [[ "$out" =~ 'No resources found' ]]; then
4242
:
4343
else

logging/bin/remove_servicemonitors_openshift.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
# Copyright © 2021, 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

9-
this_script=`basename "$0"`
9+
this_script=$(basename "$0")
1010

1111
log_debug "Script [$this_script] has started [$(date)]"
1212

@@ -21,19 +21,19 @@ fi
2121
EVENTROUTER_ENABLE=${EVENTROUTER_ENABLE:-true}
2222
if [ "$EVENTROUTER_ENABLE" == "true" ]; then
2323
# Eventrouter ServiceMonitor
24-
kubectl delete --ignore-not-found -n $LOG_NS -f monitoring/monitors/kube/podMonitor-eventrouter.yaml
24+
kubectl delete --ignore-not-found -n "$LOG_NS" -f monitoring/monitors/kube/podMonitor-eventrouter.yaml
2525
fi
2626

2727
ELASTICSEARCH_ENABLE=${ELASTICSEARCH_ENABLE:-true}
2828
if [ "$ELASTICSEARCH_ENABLE" == "true" ]; then
2929
# Elasticsearch ServiceMonitor
30-
kubectl delete --ignore-not-found -n $LOG_NS -f monitoring/monitors/logging/serviceMonitor-elasticsearch.yaml
30+
kubectl delete --ignore-not-found -n "$LOG_NS" -f monitoring/monitors/logging/serviceMonitor-elasticsearch.yaml
3131
fi
3232

3333
FLUENT_BIT_ENABLED=${FLUENT_BIT_ENABLED:-true}
3434
if [ "$FLUENT_BIT_ENABLED" == "true" ]; then
3535
# Fluent Bit ServiceMonitors
36-
kubectl delete --ignore-not-found -n $LOG_NS -f monitoring/monitors/logging/serviceMonitor-fluent-bit-v2.yaml
36+
kubectl delete --ignore-not-found -n "$LOG_NS" -f monitoring/monitors/logging/serviceMonitor-fluent-bit-v2.yaml
3737
fi
3838

3939
log_info "ServiceMonitors have been removed."

0 commit comments

Comments
 (0)