diff options
author | Andrew Kutz <101085+akutz@users.noreply.github.com> | 2021-08-24 16:45:11 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-08-24 16:45:11 -0500 |
commit | de8931edc4093013fd685938e1c4e5a3d53f653c (patch) | |
tree | 670dc8660ecd5bb7326a0ba264b3dfb3e0c4d4f6 | |
parent | 28e56d993fc40feab139f149dacc10cae51a3fe0 (diff) | |
download | vyos-cloud-init-de8931edc4093013fd685938e1c4e5a3d53f653c.tar.gz vyos-cloud-init-de8931edc4093013fd685938e1c4e5a3d53f653c.zip |
Update ds-identify to pass shellcheck (#979)
This patch updates the ds-identify file to pass the
popular shell linter, shellcheck. Updates include:
* Global ignore for error code 3043, the warning about
the "local" keyword not being POSIX compliant. This
keyword is used everywhere and cannot be easily removed.
* Point-of-use ignore for error code 3013, the warning
about the "-nt" comparator not being POSIX compliant.
There's no POSIX compliant way to compare timestamps
on two files without forking a new process, so this
comparator remains.
* Several point-of-use ignores for error code 2254, the
warning about quoting parameters. These warnings are
ignored for the *_matches functions where wildcard
tokens are expected to be used. Quoting the parameters
would prevent the desired globbing and cause calls
to these functions with wildcards to fail.
* A point-of-use ignore for error code 2086 for the
same reason as the above ignore -- allowing globbing
to take place for matching.
* Quoted parameters in the remainder of the locations
where it was safe to do so and did not break the
tests.
-rwxr-xr-x | tools/ds-identify | 35 |
1 files changed, 20 insertions, 15 deletions
diff --git a/tools/ds-identify b/tools/ds-identify index f509f566..63d2f0c8 100755 --- a/tools/ds-identify +++ b/tools/ds-identify @@ -1,5 +1,5 @@ #!/bin/sh -# shellcheck disable=2015,2039,2162,2166 +# shellcheck disable=2015,2039,2162,2166,3043 # # ds-identify is configured via /etc/cloud/ds-identify.cfg # or on the kernel command line. It takes the following inputs: @@ -615,6 +615,7 @@ read_pid1_product_name() { dmi_chassis_asset_tag_matches() { is_container && return 1 + # shellcheck disable=2254 case "${DI_DMI_CHASSIS_ASSET_TAG}" in $1) return 0;; esac @@ -623,6 +624,7 @@ dmi_chassis_asset_tag_matches() { dmi_product_name_matches() { is_container && return 1 + # shellcheck disable=2254 case "${DI_DMI_PRODUCT_NAME}" in $1) return 0;; esac @@ -631,6 +633,7 @@ dmi_product_name_matches() { dmi_product_serial_matches() { is_container && return 1 + # shellcheck disable=2254 case "${DI_DMI_PRODUCT_SERIAL}" in $1) return 0;; esac @@ -764,7 +767,7 @@ check_config() { while read line; do line=${line%%#*} case "$line" in - $key:\ *|$key:) + $key:\ *|"${key}":) ret=${line#*:}; ret=${ret# }; found=$((found+1)) @@ -812,6 +815,7 @@ dscheck_NoCloud() { check_seed_dir "$d" meta-data user-data && return ${DS_FOUND} check_writable_seed_dir "$d" meta-data user-data && return ${DS_FOUND} done + # shellcheck disable=2086 if has_fs_with_label $fslabel; then return ${DS_FOUND} fi @@ -1239,11 +1243,11 @@ dscheck_AltCloud() { ctype="${DI_DMI_PRODUCT_NAME}" fi case "$ctype" in - ${match_rhev}) + "${match_rhev}") probe_floppy || return ${DS_NOT_FOUND} dev="/dev/floppy" ;; - ${match_vsphere}) + "${match_vsphere}") block_dev_with_label CDROM || return ${DS_NOT_FOUND} dev="$_RET" ;; @@ -1309,6 +1313,7 @@ is_ibm_provisioning() { msg="config '$pcfg' exists." is_prov=true if [ -f "$logf" ]; then + # shellcheck disable=3013 if [ "$logf" -nt "$PATH_PROC_1_ENVIRON" ]; then msg="$msg log '$logf' from current boot." else @@ -1324,7 +1329,7 @@ is_ibm_provisioning() { } is_ibm_cloud() { - cached "${_IS_IBM_CLOUD}" && return ${_IS_IBM_CLOUD} + cached "${_IS_IBM_CLOUD}" && return "${_IS_IBM_CLOUD}" local ret=1 if [ "$DI_VIRT" = "xen" ]; then if is_ibm_provisioning; then @@ -1640,10 +1645,10 @@ parse_policy() { for tok in "$@"; do val=${tok#*=} case "$tok" in - $DI_ENABLED|$DI_DISABLED|search|report) mode=$tok;; + "${DI_ENABLED}"|"${DI_DISABLED}"|search|report) mode=$tok;; found=all|found=first) found=$val;; maybe=all|maybe=none) maybe=$val;; - notfound=$DI_ENABLED|notfound=$DI_DISABLED) notfound=$val;; + notfound="${DI_ENABLED}"|notfound="${DI_DISABLED}") notfound=$val;; found=*) parse_warn found "$val" "${_def_found}" found=${_def_found};; @@ -1724,11 +1729,11 @@ _main() { fi case "$DI_MODE" in - $DI_DISABLED) + "${DI_DISABLED}") debug 1 "mode=$DI_DISABLED. returning $ret_dis" return $ret_dis ;; - $DI_ENABLED) + "${DI_ENABLED}") debug 1 "mode=$DI_ENABLED. returning $ret_en" return $ret_en;; search|report) :;; @@ -1768,11 +1773,11 @@ _main() { $dscheck_fn ret="$?" case "$ret" in - $DS_FOUND) + "${DS_FOUND}") debug 1 "check for '$ds' returned found"; exfound_cfg="${exfound_cfg:+${exfound_cfg}${CR}}${_RET_excfg}" found="${found} $ds";; - $DS_MAYBE) + "${DS_MAYBE}") debug 1 "check for '$ds' returned maybe"; exmaybe_cfg="${exmaybe_cfg:+${exmaybe_cfg}${CR}}${_RET_excfg}" maybe="${maybe} $ds";; @@ -1811,16 +1816,16 @@ _main() { local basemsg="No ds found [mode=$DI_MODE, notfound=$DI_ON_NOTFOUND]." local msg="" ret=3 case "$DI_MODE:$DI_ON_NOTFOUND" in - report:$DI_DISABLED) + report:"${DI_DISABLED}") msg="$basemsg Would disable cloud-init [$ret_dis]" ret=$ret_en;; - report:$DI_ENABLED) + report:"${DI_ENABLED}") msg="$basemsg Would enable cloud-init [$ret_en]" ret=$ret_en;; - search:$DI_DISABLED) + search:"${DI_DISABLED}") msg="$basemsg Disabled cloud-init [$ret_dis]" ret=$ret_dis;; - search:$DI_ENABLED) + search:"${DI_ENABLED}") msg="$basemsg Enabled cloud-init [$ret_en]" ret=$ret_en;; *) error "Unexpected result";; |