Skip to content

Commit e53a605

Browse files
committed
Add shell check comments, Update function descriptions
Add shellcheck comments for warnings that can be safely ignored. Improve function readability by formatting them all in the same style.
1 parent 1e9d665 commit e53a605

File tree

7 files changed

+243
-89
lines changed

7 files changed

+243
-89
lines changed

pkg/deploy/generator/scripts/gatewayVMSS.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,11 @@ RPIMAGE='$rpimage'"
147147
reboot_vm
148148
}
149149

150+
# export AZURE_CLOUD_NAME="${AZURECLOUDNAME:?"Failed to carry over variables"}"
150151
export AZURE_CLOUD_NAME="${AZURECLOUDNAME:?"Failed to carry over variables"}"
151152

153+
# util="util.sh"
154+
#
152155
# util.sh does not exist when deployed to VMSS via VMSS extensions
153156
# Provides shellcheck definitions
154157
util="util.sh"

pkg/deploy/generator/scripts/rpVMSS.sh

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ main() {
88
# transaction attempt retry time in seconds
99
# shellcheck disable=SC2034
1010
local -ri retry_wait_time=30
11-
local -ri pkg_retry_count=60
1211

1312
create_required_dirs
13+
1414
configure_sshd
15+
16+
local -ri pkg_retry_count=60
1517
configure_rpm_repos retry_wait_time \
1618
"$pkg_retry_count"
1719

@@ -53,10 +55,16 @@ main() {
5355
# shellcheck disable=SC2153 disable=SC2034
5456
local -r mdmimage="${RPIMAGE%%/*}/${MDMIMAGE#*/}"
5557
local -r rpimage="$RPIMAGE"
58+
59+
# shellcheck disable=SC2034
5660
local -r miseimage="${RPIMAGE%%/*}/${MISEIMAGE#*/}"
61+
62+
# shellcheck disable=SC2034
5763
local -r otelimage="$OTELIMAGE"
64+
5865
# shellcheck disable=SC2034
5966
local -r fluentbit_image="$FLUENTBITIMAGE"
67+
6068
# shellcheck disable=SC2034
6169
local -rA aro_images=(
6270
["mdm"]="mdmimage"
@@ -214,11 +222,15 @@ MSI_RP_ENDPOINT='$MSIRPENDPOINT'
214222
reboot_vm
215223
}
216224

225+
# export AZURE_CLOUD_NAME="${AZURECLOUDNAME:?"Failed to carry over variables"}"
226+
#
217227
# This variable is used by az-cli
218228
# It's assumed that if this variable hasn't been carried over, that others are also not present, so we fail early by returning an error
219229
# This was mostly helpful when testing on a development VM, but is still applicable
220230
export AZURE_CLOUD_NAME="${AZURECLOUDNAME:?"Failed to carry over variables"}"
221231

232+
# util="util.sh"
233+
#
222234
# util.sh does not exist when deployed to VMSS via VMSS extensions
223235
# Provides shellcheck definitions
224236
util="util.sh"

pkg/deploy/generator/scripts/util-common.sh

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,36 @@ xtrace_set() {
6767
(( XTRACE_IS_SET == XTRACE_UNSET )) && set -x || return 0
6868
}
6969

70-
# log is a wrapper for echo that includes the function name
71-
# Args
72-
# 1) msg - string
73-
# 2) stack_level - int; optional, defaults to the function at the bottom of the call stack
70+
# log()
71+
#
72+
# Wrapper for echo that includes the function name
73+
# args:
74+
# 1) msg - string
75+
# 2) stack_level - int; optional
76+
# * defaults to the function at the bottom of the call stack
7477
log() {
7578
local -r msg="${1:-"log message is empty"}"
7679
local -r stack_level="${2:-1}"
7780
echo "${FUNCNAME[${stack_level}]}: ${msg}"
7881
}
7982

80-
# abort is a wrapper for log that exits with an error code
83+
# abort()
84+
#
85+
# Wrapper for log that exits with an error code
8186
abort() {
8287
local -ri origin_stacklevel=2
8388
log "${1}" "$origin_stacklevel"
8489
log "Exiting"
8590
exit 1
8691
}
8792

88-
# write_file
89-
# Args
90-
# 1) filename - string
91-
# 2) file_contents - string
92-
# 3) clobber - boolean; optional - defaults to false
93+
# write_file()
94+
#
95+
# args:
96+
# 1) filename - string
97+
# 2) file_contents - string
98+
# 3) clobber - boolean; optional
99+
# * defaults to false
93100
write_file() {
94101
local -n filename="$1"
95102
local -n file_contents="$2"
@@ -104,11 +111,16 @@ write_file() {
104111
fi
105112
}
106113

107-
# retry Adding retry logic to yum commands in order to avoid stalling out on resource locks
114+
# retry()
115+
#
116+
# Add retry logic to commands in order to avoid stalling out on resource locks
108117
# args:
109-
# 1) cmd_retry - nameref, array; Command and arguement(s) to retry
110-
# 2) wait_time - nameref, integer; Time to wait before retrying command
111-
# 3) retries - integer, optional; Ammount of times to retry command, defaults to 5
118+
# 1) cmd_retry - nameref, array
119+
# * Command and argument(s) to retry
120+
# 2) wait_time - nameref, integer
121+
# * Time to wait before retrying command
122+
# 3) retries - integer, optional
123+
# * Amount of times to retry command, defaults to 5
112124
retry() {
113125
local -n cmd_retry="$1"
114126
local -n wait_time="$2"
@@ -127,9 +139,11 @@ retry() {
127139
abort "${cmd_retry[*]} failed after #$retries attempts"
128140
}
129141

130-
# verify_role
142+
# verify_role()
143+
#
131144
# args:
132-
# 1) test_role - nameref; role being verified
145+
# 1) test_role - nameref
146+
# * role being verified
133147
verify_role() {
134148
local -n test_role="$1"
135149

@@ -141,11 +155,15 @@ verify_role() {
141155
fi
142156
}
143157

144-
# get_keyvault_suffix
158+
# get_keyvault_suffix()
159+
#
145160
# args:
146-
# 1) rl - nameref, string; role to get short role for
147-
# 2) kv_suffix - nameref, string; short role will be assigned to this nameref
148-
# 3) sec_prefix - nameref, string; keyvault certificate prefix will be assigned to this nameref
161+
# 1) rl - nameref, string;
162+
# * role to get short role for
163+
# 2) kv_suffix - nameref, string;
164+
# * short role will be assigned to this nameref
165+
# 3) sec_prefix - nameref, string;
166+
# * keyvault certificate prefix will be assigned to this nameref
149167
get_keyvault_suffix() {
150168
local -n rl="$1"
151169
local -n kv_suffix="$2"
@@ -169,9 +187,11 @@ get_keyvault_suffix() {
169187
esac
170188
}
171189

190+
# reboot_vm()
191+
#
172192
# reboot_vm restores calls shutdown -r in a subshell
173-
# Reboots should scheduled after all VM extensions have had time to complete
174-
# Reference: https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-linux#tips
193+
# * Reboots should scheduled after all VM extensions have had time to complete
194+
# * Reference: https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-linux#tips
175195
reboot_vm() {
176196
log "starting"
177197

pkg/deploy/generator/scripts/util-packages.sh

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/bin/bash
22
# Repository and package management related functions
33

4+
# configure_repo_mariner_extended()
45
configure_repo_mariner_extended() {
56
local -r extended_repo_config="https://packages.microsoft.com/cbl-mariner/2.0/prod/extended/x86_64/config.repo"
67
curl -sSL "$extended_repo_config" -o /etc/yum.repos.d/mariner-extended.repo
@@ -19,21 +20,28 @@ configure_repo_mariner_extended() {
1920
}
2021

2122
# configure_rpm_repos
23+
#
2224
# New repositories should be added in their own functions, and called here
2325
# args:
24-
# 1) wait_time - nameref, integer; Time to wait before retrying command
25-
# 2) retries - integer, optional; Amount of times to retry command, defaults to 5
26+
# 1) wait_time - nameref, integer
27+
# * Time to wait before retrying command
28+
# 2) retries - integer, optional
29+
# * Amount of times to retry command, defaults to 5
2630
configure_rpm_repos() {
2731
log "starting"
2832

2933
configure_repo_mariner_extended "$1" "${2:-1}"
3034
}
3135

3236
# dnf_install_pkgs
37+
#
3338
# args:
34-
# 1) pkgs - nameref, string array; Packages to be installed
35-
# 2) wait_time - nameref, integer; Time to wait before retrying command
36-
# 3) retries - integer, optional; Amount of times to retry command, defaults to 5
39+
# 1) pkgs - nameref, string array
40+
# * Packages to be installed
41+
# 2) wait_time - nameref, integer
42+
# * Time to wait before retrying command
43+
# 3) retries - integer, optional
44+
# * Amount of times to retry command, defaults to 5
3745
dnf_install_pkgs() {
3846
local -n pkgs="$1"
3947
log "starting"
@@ -55,11 +63,15 @@ dnf_install_pkgs() {
5563

5664

5765
# dnf_update_pkgs
66+
#
5867
# args:
59-
# 1) excludes - nameref, string array, optional; Packages to exclude from updating
60-
# Each index must be prefixed with -x
61-
# 2) wait_time - nameref, integer; Time to wait before retrying command
62-
# 3) retries - integer, optional; Ammount of times to retry command, defaults to 5
68+
# 1) excludes - nameref, string array, optional
69+
# * Packages to exclude from updating
70+
# * Each index must be prefixed with -x
71+
# 2) wait_time - nameref, integer
72+
# * Time to wait before retrying command
73+
# 3) retries - integer, optional
74+
# * Ammount of times to retry command, defaults to 5
6375
dnf_update_pkgs() {
6476
local -n excludes="${1:-empty_str}"
6577
log "starting"
@@ -87,9 +99,12 @@ dnf_update_pkgs() {
8799
}
88100

89101
# rpm_import_keys
102+
#
90103
# args:
91-
# 1) keys - nameref, string array; rpm keys to be imported
92-
# 2) wait_time - nameref, integer; Time to wait before retrying command
104+
# 1) keys - nameref, string array
105+
# * rpm keys to be imported
106+
# 2) wait_time - nameref, integer
107+
# * Time to wait before retrying command
93108
rpm_import_keys() {
94109
local -n keys="$1"
95110
log "starting"
@@ -112,6 +127,8 @@ rpm_import_keys() {
112127
done
113128
}
114129

130+
# util_common="util-common.sh"
131+
#
115132
# util-common.sh does not exist when deployed to VMSS via VMSS extensions
116133
# Provides shellcheck definitions
117134
util_common="util-common.sh"

0 commit comments

Comments
 (0)