Skip to content

Commit 572b6b8

Browse files
committed
Housekeeping: lint remaining scripts in bin
1 parent 34e1f71 commit 572b6b8

File tree

4 files changed

+135
-132
lines changed

4 files changed

+135
-132
lines changed

bin/airgap-include.sh

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

@@ -17,22 +18,22 @@ if [ "$AIRGAP_SOURCED" == "" ]; then
1718

1819
# Check for the image pull secret for the air gap environment
1920
if [ -z "$(kubectl get secret -n $V4M_NS $AIRGAP_IMAGE_PULL_SECRET_NAME -o name --ignore-not-found)" ]; then
20-
log_error "The image pull secret, [$AIRGAP_IMAGE_PULL_SECRET_NAME], was not detected"
21-
log_error "Please add the image pull secret to the [$V4M_NS] namespace and run the deployment script again"
22-
exit 1
21+
log_error "The image pull secret, [$AIRGAP_IMAGE_PULL_SECRET_NAME], was not detected"
22+
log_error "Please add the image pull secret to the [$V4M_NS] namespace and run the deployment script again"
23+
exit 1
2324
fi
2425

2526
AIRGAP_HELM_REPO=${AIRGAP_HELM_REPO:-"$AIRGAP_REGISTRY"}
2627
AIRGAP_HELM_FORMAT=${AIRGAP_HELM_FORMAT:-"oci"}
2728

2829
if [ "$AIRGAP_HELM_FORMAT" == "tgz" ]; then
29-
if [ ! -d "$AIRGAP_HELM_REPO" ]; then
30-
log_error "When AIRGAP_HELM_FORMAT is 'tgz', AIRGAP_HELM_REPO is expected to be a directory."
31-
log_error "The specified AIRGAP_HELM_REPO directory [$AIRGAP_HELM_REPO] does NOT exist."
32-
exit 1
33-
else
34-
log_debug "Confirmed AIRGAP_HELM_REPO [$AIRGAP_HELM_REPO] exists"
35-
fi
30+
if [ ! -d "$AIRGAP_HELM_REPO" ]; then
31+
log_error "When AIRGAP_HELM_FORMAT is 'tgz', AIRGAP_HELM_REPO is expected to be a directory."
32+
log_error "The specified AIRGAP_HELM_REPO directory [$AIRGAP_HELM_REPO] does NOT exist."
33+
exit 1
34+
else
35+
log_debug "Confirmed AIRGAP_HELM_REPO [$AIRGAP_HELM_REPO] exists"
36+
fi
3637
fi
3738
fi
3839

@@ -43,4 +44,3 @@ if [ "$AIRGAP_SOURCED" == "" ]; then
4344

4445
export AIRGAP_SOURCED=true
4546
fi
46-

bin/colors-include.sh

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

bin/configure_nodeport.sh

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

3-
# Copyright © 2022, SAS Institute Inc., Cary, NC, USA. All Rights Reserved.
3+
# 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")/.."
77
source logging/bin/common.sh
88

99
#TO DO: Should be done in bin/common?
@@ -12,11 +12,11 @@ export MON_NS="${MON_NS:-monitoring}"
1212

1313
# Confirm NOT on OpenShift
1414
if [ "$OPENSHIFT_CLUSTER" == "true" ]; then
15-
if [ "${CHECK_OPENSHIFT_CLUSTER:-true}" == "true" ]; then
16-
log_error "This script should NOT be run on OpenShift clusters"
17-
log_error "Run 'logging/bin/create_openshift_route.sh' instead"
18-
exit 1
19-
fi
15+
if [ "${CHECK_OPENSHIFT_CLUSTER:-true}" == "true" ]; then
16+
log_error "This script should NOT be run on OpenShift clusters"
17+
log_error "Run 'logging/bin/create_openshift_route.sh' instead"
18+
exit 1
19+
fi
2020
fi
2121

2222
set -e
@@ -28,17 +28,17 @@ arg2=${2}
2828
arg2=$(echo "$arg2"| tr '[:lower:]' '[:upper:]')
2929

3030
if [[ "$arg2" -ge 30000 ]] && [[ "$arg2" -le 32767 ]]; then
31-
log_debug "Requested port [$target_port] is within valid range"
32-
target_port="$arg2"
31+
log_debug "Requested port [$target_port] is within valid range"
32+
target_port="$arg2"
3333
elif [ "$arg2" == "0" ]; then
34-
log_debug "Random port requested"
35-
target_port="0"
34+
log_debug "Random port requested"
35+
target_port="0"
3636
elif [ "$arg2" == "DISABLE" ] || [ -z "$arg2" ]; then
37-
log_debug "2nd argument: $arg2"
37+
log_debug "2nd argument: $arg2"
3838
else
39-
log_error "Invalid 2nd argument provided."
40-
log_error "Value must be: a port number between 30000 and 32767, 0 (a random port will be assigned) or DISABLE (disable the current nodePort). "
41-
exit 1
39+
log_error "Invalid 2nd argument provided."
40+
log_error "Value must be: a port number between 30000 and 32767, 0 (a random port will be assigned) or DISABLE (disable the current nodePort). "
41+
exit 1
4242
fi
4343

4444
app=$(echo "$app"| tr '[:lower:]' '[:upper:]')
@@ -94,20 +94,20 @@ case "$app" in
9494
esac
9595

9696
if [ "$arg2" == "DISABLE" ];then
97-
log_info "Removing NodePort for [$servicename] in [$LOG_NS]"
98-
kubectl -n "$namespace" patch svc "$servicename" --type='json' -p '[{"op":"replace","path":"/spec/type","value":"ClusterIP"}]'
99-
exit
97+
log_info "Removing NodePort for [$servicename] in [$LOG_NS]"
98+
kubectl -n "$namespace" patch svc "$servicename" --type='json' -p '[{"op":"replace","path":"/spec/type","value":"ClusterIP"}]'
99+
exit
100100
elif [ "$target_port" != "0" ]; then
101-
log_info "Making [$servicename] in [$namespace] namespace available on port [$target_port]"
102-
echo
101+
log_info "Making [$servicename] in [$namespace] namespace available on port [$target_port]"
102+
echo
103103
else
104-
log_debug "No specific port was provided, will make [$servicename] available on a random port"
104+
log_debug "No specific port was provided, will make [$servicename] available on a random port"
105105
fi
106106

107107
kubectl -n "$namespace" patch svc "$servicename" --type='json' -p '[{"op":"replace","path":"/spec/type","value":"NodePort"}]'
108-
kubectl -n "$namespace" patch svc "$servicename" --type='json' -p '[{"op":"replace","path":"/spec/ports/0/nodePort","value":'${target_port}'}]'
108+
kubectl -n "$namespace" patch svc "$servicename" --type='json' -p '[{"op":"replace","path":"/spec/ports/0/nodePort","value":'"${target_port}"'}]'
109109

110110
show_url="${SHOW_URL:-true}"
111111
if [ "$show_url" == "true" ]; then
112-
bin/show_app_url.sh $appname
112+
bin/show_app_url.sh $appname
113113
fi

bin/openshift-include.sh

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

45
# This script is not intended to be run directly
56
# Assumes bin/common.sh has been sourced
67

78
function ocVersionCheck {
8-
origIFS=$IFS
9-
IFS=$'\n'
9+
origIFS=$IFS
10+
IFS=$'\n'
1011

11-
allArr=($(oc version 2>/dev/null))
12-
IFS=$origIFS
12+
# shellcheck disable=SC2207
13+
allArr=($(oc version 2>/dev/null))
14+
IFS=$origIFS
1315

14-
for (( i=0; i<${#allArr[@]}; i++ )); do
15-
# Split the line into an array
16-
verArr=(${allArr[$i]})
17-
if [ ${#verArr[@]} -eq 3 ]; then
18-
verType="${verArr[0]}"
19-
ver="${verArr[2]}"
20-
if [ "$verType" == "Client" ]; then
21-
ver="${verArr[2]}"
22-
if [[ $ver =~ v?(([0-9]+)\.([0-9]+)\.([0-9]+)) ]]; then
23-
OC_FULL_VERSION=${BASH_REMATCH[1]}
24-
OC_MAJOR_VERSION=${BASH_REMATCH[2]}
25-
OC_MINOR_VERSION=${BASH_REMATCH[3]}
26-
OC_PATCH_VERSION=${BASH_REMATCH[4]}
27-
else
28-
echo "Unable to parse client version: [$ver]"
29-
fi
30-
elif [ "$verType" == "Server" ]; then
31-
ver="${verArr[2]}"
32-
if [[ $ver =~ (([0-9]+)\.([0-9]+)\.([0-9]+)) ]]; then
33-
OSHIFT_FULL_VERSION=${BASH_REMATCH[1]}
34-
OSHIFT_MAJOR_VERSION=${BASH_REMATCH[2]}
35-
OSHIFT_MINOR_VERSION=${BASH_REMATCH[3]}
36-
OSHIFT_PATCH_VERSION=${BASH_REMATCH[4]}
37-
else
38-
echo "Unable to parse server version: [$ver]"
39-
fi
40-
fi
41-
fi
42-
done
43-
log_info "OpenShift client version: $OC_FULL_VERSION"
44-
log_info "OpenShift server version: $OSHIFT_FULL_VERSION"
45-
46-
# Version enforcement
47-
if [ "$OPENSHIFT_VERSION_CHECK" == "true" ]; then
48-
## Server Version
49-
### Openshift versions that do not start with a 4 should produce an error.
50-
if (( "$OSHIFT_MAJOR_VERSION" != 4 )); then
51-
log_error "Unsupported OpenShift server version: $OSHIFT_FULL_VERSION"
52-
log_error "Version 4.12+ is required"
53-
exit 1
54-
### 21FEB24: Openshift 4 versions earlier than 4.12 should produce an error.
55-
elif (( "$OSHIFT_MINOR_VERSION" < 12 )); then
56-
log_error "Unsupported OpenShift server version: $OSHIFT_FULL_VERSION"
57-
log_error "Version 4.12+ is required"
58-
exit 1
59-
else
60-
log_debug "OpenShift server version check OK"
61-
fi
16+
for (( i=0; i<${#allArr[@]}; i++ )); do
17+
# Split the line into an array
18+
verArr=("${allArr[$i]}")
19+
if [ ${#verArr[@]} -eq 3 ]; then
20+
verType="${verArr[0]}"
21+
ver="${verArr[2]}"
22+
if [ "$verType" == "Client" ]; then
23+
ver="${verArr[2]}"
24+
if [[ $ver =~ v?(([0-9]+)\.([0-9]+)\.([0-9]+)) ]]; then
25+
OC_FULL_VERSION=${BASH_REMATCH[1]}
26+
OC_MAJOR_VERSION=${BASH_REMATCH[2]}
27+
OC_MINOR_VERSION=${BASH_REMATCH[3]}
28+
OC_PATCH_VERSION=${BASH_REMATCH[4]}
29+
else
30+
echo "Unable to parse client version: [$ver]"
31+
fi
32+
elif [ "$verType" == "Server" ]; then
33+
ver="${verArr[2]}"
34+
if [[ $ver =~ (([0-9]+)\.([0-9]+)\.([0-9]+)) ]]; then
35+
OSHIFT_FULL_VERSION=${BASH_REMATCH[1]}
36+
OSHIFT_MAJOR_VERSION=${BASH_REMATCH[2]}
37+
OSHIFT_MINOR_VERSION=${BASH_REMATCH[3]}
38+
OSHIFT_PATCH_VERSION=${BASH_REMATCH[4]}
39+
else
40+
echo "Unable to parse server version: [$ver]"
41+
fi
42+
fi
43+
fi
44+
done
45+
log_info "OpenShift client version: $OC_FULL_VERSION"
46+
log_info "OpenShift server version: $OSHIFT_FULL_VERSION"
6247

63-
## Client Version
64-
### Openshift versions that do not start with a 4 should produce an error.
65-
if (( "$OC_MAJOR_VERSION" != 4 )); then
66-
log_error "Unsupported OpenShift client version: $OC_FULL_VERSION"
67-
log_error "Version 4.11+ is required"
68-
exit 1
69-
### Openshift 4 client version must be w/in 1 minor releases of server minimum.
70-
elif (( "$OC_MINOR_VERSION" < 11 )); then
71-
log_error "Unsupported OpenShift client version: $OC_FULL_VERSION"
72-
log_error "Version 4.11+ is required"
73-
exit 1
74-
else
75-
log_debug "OpenShift client version check OK"
48+
# Version enforcement
49+
if [ "$OPENSHIFT_VERSION_CHECK" == "true" ]; then
50+
## Server Version
51+
### Openshift versions that do not start with a 4 should produce an error.
52+
if (( OSHIFT_MAJOR_VERSION != 4 )); then
53+
log_error "Unsupported OpenShift server version: $OSHIFT_FULL_VERSION"
54+
log_error "Version 4.12+ is required"
55+
exit 1
56+
### 21FEB24: Openshift 4 versions earlier than 4.12 should produce an error.
57+
elif (( OSHIFT_MINOR_VERSION < 12 )); then
58+
log_error "Unsupported OpenShift server version: $OSHIFT_FULL_VERSION"
59+
log_error "Version 4.12+ is required"
60+
exit 1
61+
else
62+
log_debug "OpenShift server version check OK"
63+
fi
64+
65+
## Client Version
66+
### Openshift versions that do not start with a 4 should produce an error.
67+
if (( OC_MAJOR_VERSION != 4 )); then
68+
log_error "Unsupported OpenShift client version: $OC_FULL_VERSION"
69+
log_error "Version 4.11+ is required"
70+
exit 1
71+
### Openshift 4 client version must be w/in 1 minor releases of server minimum.
72+
elif (( OC_MINOR_VERSION < 11 )); then
73+
log_error "Unsupported OpenShift client version: $OC_FULL_VERSION"
74+
log_error "Version 4.11+ is required"
75+
exit 1
76+
else
77+
log_debug "OpenShift client version check OK"
78+
fi
7679
fi
77-
fi
7880
}
7981

8082
OPENSHIFT_VERSION_CHECK=${OPENSHIFT_VERSION_CHECK:-true}
8183
if [ "$SAS_OPENSHIFT_SOURCED" != "true" ]; then
82-
if [ "$OPENSHIFT_CLUSTER" == "" ]; then
83-
# Detect OpenShift cluster
84-
if kubectl get ns openshift 2>/dev/null 1>&2; then
85-
log_debug "OpenShift detected"
86-
OPENSHIFT_CLUSTER="true"
84+
if [ "$OPENSHIFT_CLUSTER" == "" ]; then
85+
# Detect OpenShift cluster
86+
if kubectl get ns openshift 2>/dev/null 1>&2; then
87+
log_debug "OpenShift detected"
88+
OPENSHIFT_CLUSTER="true"
89+
else
90+
log_debug "OpenShift not detected"
91+
OPENSHIFT_CLUSTER="false"
92+
fi
8793
else
88-
log_debug "OpenShift not detected"
89-
OPENSHIFT_CLUSTER="false"
94+
log_debug "Skipping OpenShift detection. OPENSHIFT_CLUSTER=[$OPENSHIFT_CLUSTER]"
9095
fi
91-
else
92-
log_debug "Skipping OpenShift detection. OPENSHIFT_CLUSTER=[$OPENSHIFT_CLUSTER]"
93-
fi
9496

95-
if [ "$OPENSHIFT_CLUSTER" == "true" ]; then
96-
if [ "${OPENSHIFT_OC_CHECK:-true}" == "true" ]; then
97-
if [ ! $(which oc) ]; then
98-
echo "'oc' is required for OpenShift and not found on the current PATH"
99-
exit 1
100-
fi
101-
ocVersionCheck
97+
if [ "$OPENSHIFT_CLUSTER" == "true" ]; then
98+
if [ "${OPENSHIFT_OC_CHECK:-true}" == "true" ]; then
99+
if ! which oc 1>/dev/null ; then
100+
echo "'oc' is required for OpenShift and not found on the current PATH"
101+
exit 1
102+
fi
103+
ocVersionCheck
102104

103-
# Get base OpenShift route hostname
104-
OPENSHIFT_ROUTE_DOMAIN=${OPENSHIFT_ROUTE_DOMAIN:-$(oc get route -n openshift-console console -o 'jsonpath={.spec.host}' | cut -c 27-)}
105-
if [ "$OPENSHIFT_ROUTE_DOMAIN" != "" ]; then
106-
log_debug "OpenShift route host is [$OPENSHIFT_ROUTE_DOMAIN]"
107-
else
108-
log_error "Unable to determine OpenShift route host. Set OPENSHIFT_ROUTE_DOMAIN if necessary."
109-
exit 1
110-
fi
105+
# Get base OpenShift route hostname
106+
OPENSHIFT_ROUTE_DOMAIN=${OPENSHIFT_ROUTE_DOMAIN:-$(oc get route -n openshift-console console -o 'jsonpath={.spec.host}' | cut -c 27-)}
107+
if [ "$OPENSHIFT_ROUTE_DOMAIN" != "" ]; then
108+
log_debug "OpenShift route host is [$OPENSHIFT_ROUTE_DOMAIN]"
109+
else
110+
log_error "Unable to determine OpenShift route host. Set OPENSHIFT_ROUTE_DOMAIN if necessary."
111+
exit 1
112+
fi
111113

112-
export OPENSHIFT_ROUTE_DOMAIN
113-
export OC_MAJOR_VERSION OC_MINOR_VERSION OC_PATCH_VERSION
114-
export OSHIFT_MAJOR_VERSION OSHIFT_MINOR_VERSION OSHIFT_PATCH_VERSION
115-
fi
116-
else
114+
export OPENSHIFT_ROUTE_DOMAIN
115+
export OC_MAJOR_VERSION OC_MINOR_VERSION OC_PATCH_VERSION
116+
export OSHIFT_MAJOR_VERSION OSHIFT_MINOR_VERSION OSHIFT_PATCH_VERSION
117+
fi
118+
else
117119
log_debug "OpenShift not detected. Skipping 'oc' checks."
118-
fi
119-
export OPENSHIFT_CLUSTER
120+
fi
121+
export OPENSHIFT_CLUSTER
120122
export SAS_OPENSHIFT_SOURCED="true"
121123
fi

0 commit comments

Comments
 (0)