Merge ~smoser/cloud-init:cleanup/ds-identify-shellcheck-fixes into cloud-init:master

Proposed by Scott Moser
Status: Merged
Approved by: Scott Moser
Approved revision: c172d647ab5e11b2afc55126705aac1ee17ea911
Merge reported by: Scott Moser
Merged at revision: 4c1af5c7eb8db67f51f35130e13157a735256d2b
Proposed branch: ~smoser/cloud-init:cleanup/ds-identify-shellcheck-fixes
Merge into: cloud-init:master
Diff against target: 216 lines (+32/-18)
1 file modified
tools/ds-identify (+32/-18)
Reviewer Review Type Date Requested Status
Scott Moser Approve
Server Team CI bot continuous-integration Approve
Review via email: mp+344768@code.launchpad.net

Commit message

ds-identify: make shellcheck 0.4.6 happy with ds-identify.

This fixes warnings reported by shellcheck at 0.4.6.
The complaints that we are ignoring globally (top of the file) are:
 2015: Note that A && B || C is not if-then-else. C may run if A is true.
 2039: In POSIX sh, 'local' is undefined.
 2162: read without -r will mangle backslashes.
 2166: Prefer [ p ] && [ q ] as [ p -a q ] is not well defined.

Most of the complaints were just noise, but a few unused variables
were reported and fixed.

Related shellcheck issues opened:
 - https://github.com/koalaman/shellcheck/issues/1191
 - https://github.com/koalaman/shellcheck/issues/1192
 - https://github.com/koalaman/shellcheck/issues/1193
 - https://github.com/koalaman/shellcheck/issues/1194

Description of the change

see commit message

To post a comment you must log in.
Revision history for this message
Scott Moser (smoser) wrote :

In the process of doing this I filed 4 issues (2 bugs, 2 feature requests)

 - https://github.com/koalaman/shellcheck/issues/1191
 - https://github.com/koalaman/shellcheck/issues/1192
 - https://github.com/koalaman/shellcheck/issues/1193
 - https://github.com/koalaman/shellcheck/issues/1194

Things I am not terribly happy about:
 * don't know how to run this from tox or c-i and get a 'shellcheck-tip' and 'shellchec' style targets.
 * I don't love the '# shellcheck disable' noise. perhaps we could strip them out when installing.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:f99b8c8143b35606895c9354edd7e3fb33134640
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1072/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1072/rebuild

review: Approve (continuous-integration)
Revision history for this message
Ryan Harper (raharper) wrote :

LGTM, some nits inline.

Revision history for this message
Server Team CI bot (server-team-bot) wrote :

PASSED: Continuous integration, rev:c172d647ab5e11b2afc55126705aac1ee17ea911
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1075/
Executed test runs:
    SUCCESS: Checkout
    SUCCESS: Unit & Style Tests
    SUCCESS: Ubuntu LTS: Build
    SUCCESS: Ubuntu LTS: Integration
    SUCCESS: MAAS Compatability Testing
    IN_PROGRESS: Declarative: Post Actions

Click here to trigger a rebuild:
https://jenkins.ubuntu.com/server/job/cloud-init-ci/1075/rebuild

review: Approve (continuous-integration)
Revision history for this message
Scott Moser (smoser) wrote :

based on Ryan's lgtm.

review: Approve
Revision history for this message
Scott Moser (smoser) wrote :

An upstream commit landed for this bug.

To view that commit see the following URL:
https://git.launchpad.net/cloud-init/commit/?id=4c1af5c7

There was an error fetching revisions from git servers. Please try again in a few minutes. If the problem persists, contact Launchpad support.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/tools/ds-identify b/tools/ds-identify
index 7fff5d1..4e871c0 100755
--- a/tools/ds-identify
+++ b/tools/ds-identify
@@ -1,4 +1,5 @@
1#!/bin/sh1#!/bin/sh
2# shellcheck disable=2015,2039,2162,2166
2#3#
3# ds-identify is configured via /etc/cloud/ds-identify.cfg4# ds-identify is configured via /etc/cloud/ds-identify.cfg
4# or on the kernel command line. It takes primarily 2 inputs:5# or on the kernel command line. It takes primarily 2 inputs:
@@ -125,7 +126,6 @@ DI_ON_NOTFOUND=""
125DI_EC2_STRICT_ID_DEFAULT="true"126DI_EC2_STRICT_ID_DEFAULT="true"
126127
127_IS_IBM_CLOUD=""128_IS_IBM_CLOUD=""
128_IS_IBM_PROVISIONING=""
129129
130error() {130error() {
131 set -- "ERROR:" "$@";131 set -- "ERROR:" "$@";
@@ -211,7 +211,9 @@ read_fs_info() {
211 # 'set --' will collapse multiple consecutive entries in IFS for211 # 'set --' will collapse multiple consecutive entries in IFS for
212 # whitespace characters (\n, tab, " ") so we cannot rely on getting212 # whitespace characters (\n, tab, " ") so we cannot rely on getting
213 # empty lines in "$@" below.213 # empty lines in "$@" below.
214 IFS="$CR"; set -- $out; IFS="$oifs"214
215 # shellcheck disable=2086
216 { IFS="$CR"; set -- $out; IFS="$oifs"; }
215217
216 for line in "$@"; do218 for line in "$@"; do
217 case "${line}" in219 case "${line}" in
@@ -311,6 +313,7 @@ read_dmi_product_serial() {
311 DI_DMI_PRODUCT_SERIAL="$_RET"313 DI_DMI_PRODUCT_SERIAL="$_RET"
312}314}
313315
316# shellcheck disable=2034
314read_uname_info() {317read_uname_info() {
315 # run uname, and parse output.318 # run uname, and parse output.
316 # uname is tricky to parse as it outputs always in a given order319 # uname is tricky to parse as it outputs always in a given order
@@ -330,6 +333,7 @@ read_uname_info() {
330 return $ret333 return $ret
331 }334 }
332 fi335 fi
336 # shellcheck disable=2086
333 set -- $out337 set -- $out
334 DI_UNAME_KERNEL_NAME="$1"338 DI_UNAME_KERNEL_NAME="$1"
335 DI_UNAME_NODENAME="$2"339 DI_UNAME_NODENAME="$2"
@@ -357,7 +361,8 @@ parse_yaml_array() {
357 # the fix was to quote the open bracket (val=${val#"["}) (LP: #1689648)361 # the fix was to quote the open bracket (val=${val#"["}) (LP: #1689648)
358 val=${val#"["}362 val=${val#"["}
359 val=${val%"]"}363 val=${val%"]"}
360 IFS=","; set -- $val; IFS="$oifs"364 # shellcheck disable=2086
365 { IFS=","; set -- $val; IFS="$oifs"; }
361 for tok in "$@"; do366 for tok in "$@"; do
362 trim "$tok"367 trim "$tok"
363 unquote "$_RET"368 unquote "$_RET"
@@ -393,7 +398,7 @@ read_datasource_list() {
393 fi398 fi
394 if [ -z "$dslist" ]; then399 if [ -z "$dslist" ]; then
395 dslist=${DI_DSLIST_DEFAULT}400 dslist=${DI_DSLIST_DEFAULT}
396 debug 1 "no datasource_list found, using default:" $dslist401 debug 1 "no datasource_list found, using default: $dslist"
397 fi402 fi
398 DI_DSLIST=$dslist403 DI_DSLIST=$dslist
399 return 0404 return 0
@@ -404,7 +409,8 @@ read_pid1_product_name() {
404 cached "${DI_PID_1_PRODUCT_NAME}" && return409 cached "${DI_PID_1_PRODUCT_NAME}" && return
405 [ -r "${PATH_PROC_1_ENVIRON}" ] || return410 [ -r "${PATH_PROC_1_ENVIRON}" ] || return
406 out=$(tr '\0' '\n' <"${PATH_PROC_1_ENVIRON}")411 out=$(tr '\0' '\n' <"${PATH_PROC_1_ENVIRON}")
407 IFS="$CR"; set -- $out; IFS="$oifs"412 # shellcheck disable=2086
413 { IFS="$CR"; set -- $out; IFS="$oifs"; }
408 for tok in "$@"; do414 for tok in "$@"; do
409 key=${tok%%=*}415 key=${tok%%=*}
410 [ "$key" != "$tok" ] || continue416 [ "$key" != "$tok" ] || continue
@@ -471,6 +477,7 @@ nocase_equal() {
471 [ "$1" = "$2" ] && return 0477 [ "$1" = "$2" ] && return 0
472478
473 local delim="-delim-"479 local delim="-delim-"
480 # shellcheck disable=2018,2019
474 out=$(echo "$1${delim}$2" | tr A-Z a-z)481 out=$(echo "$1${delim}$2" | tr A-Z a-z)
475 [ "${out#*${delim}}" = "${out%${delim}*}" ]482 [ "${out#*${delim}}" = "${out%${delim}*}" ]
476}483}
@@ -547,11 +554,13 @@ check_config() {
547 else554 else
548 files="$*"555 files="$*"
549 fi556 fi
550 set +f; set -- $files; set -f;557 # shellcheck disable=2086
558 { set +f; set -- $files; set -f; }
551 if [ "$1" = "$files" -a ! -f "$1" ]; then559 if [ "$1" = "$files" -a ! -f "$1" ]; then
552 return 1560 return 1
553 fi561 fi
554 local fname="" line="" ret="" found=0 found_fn=""562 local fname="" line="" ret="" found=0 found_fn=""
563 # shellcheck disable=2094
555 for fname in "$@"; do564 for fname in "$@"; do
556 [ -f "$fname" ] || continue565 [ -f "$fname" ] || continue
557 while read line; do566 while read line; do
@@ -787,7 +796,7 @@ ec2_read_strict_setting() {
787 # 3. look for the key 'strict_id' (datasource/Ec2/strict_id)796 # 3. look for the key 'strict_id' (datasource/Ec2/strict_id)
788 # only in cloud.cfg or cloud.cfg.d/EC2.cfg (case insensitive)797 # only in cloud.cfg or cloud.cfg.d/EC2.cfg (case insensitive)
789 local cfg="${PATH_ETC_CI_CFG}" cfg_d="${PATH_ETC_CI_CFG_D}"798 local cfg="${PATH_ETC_CI_CFG}" cfg_d="${PATH_ETC_CI_CFG_D}"
790 if check_config strict_id $cfg "$cfg_d/*[Ee][Cc]2*.cfg"; then799 if check_config strict_id "$cfg" "$cfg_d/*[Ee][Cc]2*.cfg"; then
791 debug 2 "${_RET_fname} set strict_id to $_RET"800 debug 2 "${_RET_fname} set strict_id to $_RET"
792 return 0801 return 0
793 fi802 fi
@@ -994,7 +1003,7 @@ dscheck_Scaleway() {
994 *\ scaleway\ *) return ${DS_FOUND};;1003 *\ scaleway\ *) return ${DS_FOUND};;
995 esac1004 esac
9961005
997 if [ -f ${PATH_ROOT}/var/run/scaleway ]; then1006 if [ -f "${PATH_ROOT}/var/run/scaleway" ]; then
998 return ${DS_FOUND}1007 return ${DS_FOUND}
999 fi1008 fi
10001009
@@ -1149,6 +1158,7 @@ found() {
1149}1158}
11501159
1151trim() {1160trim() {
1161 # shellcheck disable=2048,2086
1152 set -- $*1162 set -- $*
1153 _RET="$*"1163 _RET="$*"
1154}1164}
@@ -1169,7 +1179,7 @@ _read_config() {
1169 # if no parameters are set, modifies _rc scoped environment vars.1179 # if no parameters are set, modifies _rc scoped environment vars.
1170 # if keyname is provided, then returns found value of that key.1180 # if keyname is provided, then returns found value of that key.
1171 local keyname="${1:-_unset}"1181 local keyname="${1:-_unset}"
1172 local line="" hash="#" ckey="" key="" val=""1182 local line="" hash="#" key="" val=""
1173 while read line; do1183 while read line; do
1174 line=${line%%${hash}*}1184 line=${line%%${hash}*}
1175 key="${line%%:*}"1185 key="${line%%:*}"
@@ -1247,7 +1257,8 @@ parse_policy() {
12471257
1248 local mode="" report="" found="" maybe="" notfound=""1258 local mode="" report="" found="" maybe="" notfound=""
1249 local oifs="$IFS" tok="" val=""1259 local oifs="$IFS" tok="" val=""
1250 IFS=","; set -- $policy; IFS="$oifs"1260 # shellcheck disable=2086
1261 { IFS=","; set -- $policy; IFS="$oifs"; }
1251 for tok in "$@"; do1262 for tok in "$@"; do
1252 val=${tok#*=}1263 val=${tok#*=}
1253 case "$tok" in1264 case "$tok" in
@@ -1314,15 +1325,15 @@ manual_clean_and_existing() {
1314}1325}
13151326
1316read_uptime() {1327read_uptime() {
1317 local up idle1328 local up _
1318 _RET="${UNAVAILABLE}"1329 _RET="${UNAVAILABLE}"
1319 [ -f "$PATH_PROC_UPTIME" ] &&1330 [ -f "$PATH_PROC_UPTIME" ] && read up _ < "$PATH_PROC_UPTIME" &&
1320 read up idle < "$PATH_PROC_UPTIME" && _RET="$up"1331 _RET="$up"
1321 return1332 return
1322}1333}
13231334
1324_main() {1335_main() {
1325 local dscheck="" ret_dis=1 ret_en=01336 local dscheck_fn="" ret_dis=1 ret_en=0
13261337
1327 read_uptime1338 read_uptime
1328 debug 1 "[up ${_RET}s]" "ds-identify $*"1339 debug 1 "[up ${_RET}s]" "ds-identify $*"
@@ -1357,8 +1368,9 @@ _main() {
1357 return1368 return
1358 fi1369 fi
13591370
1360 # if there is only a single entry in $DI_DSLIST1371 # shellcheck disable=2086
1361 set -- $DI_DSLIST1372 set -- $DI_DSLIST
1373 # if there is only a single entry in $DI_DSLIST
1362 if [ $# -eq 1 ] || [ $# -eq 2 -a "$2" = "None" ] ; then1374 if [ $# -eq 1 ] || [ $# -eq 2 -a "$2" = "None" ] ; then
1363 debug 1 "single entry in datasource_list ($DI_DSLIST) use that."1375 debug 1 "single entry in datasource_list ($DI_DSLIST) use that."
1364 found "$@"1376 found "$@"
@@ -1391,6 +1403,7 @@ _main() {
1391 done1403 done
13921404
1393 debug 2 "found=${found# } maybe=${maybe# }"1405 debug 2 "found=${found# } maybe=${maybe# }"
1406 # shellcheck disable=2086
1394 set -- $found1407 set -- $found
1395 if [ $# -ne 0 ]; then1408 if [ $# -ne 0 ]; then
1396 if [ $# -eq 1 ]; then1409 if [ $# -eq 1 ]; then
@@ -1406,6 +1419,7 @@ _main() {
1406 return1419 return
1407 fi1420 fi
14081421
1422 # shellcheck disable=2086
1409 set -- $maybe1423 set -- $maybe
1410 if [ $# -ne 0 -a "${DI_ON_MAYBE}" != "none" ]; then1424 if [ $# -ne 0 -a "${DI_ON_MAYBE}" != "none" ]; then
1411 debug 1 "$# datasources returned maybe: $*"1425 debug 1 "$# datasources returned maybe: $*"
@@ -1434,7 +1448,7 @@ _main() {
1434 *) error "Unexpected result";;1448 *) error "Unexpected result";;
1435 esac1449 esac
1436 debug 1 "$msg"1450 debug 1 "$msg"
1437 return $ret1451 return "$ret"
1438}1452}
14391453
1440main() {1454main() {
@@ -1445,7 +1459,7 @@ main() {
1445 if read ret < "$PATH_RUN_DI_RESULT"; then1459 if read ret < "$PATH_RUN_DI_RESULT"; then
1446 if [ "$ret" = "0" ] || [ "$ret" = "1" ]; then1460 if [ "$ret" = "0" ] || [ "$ret" = "1" ]; then
1447 debug 2 "used cached result $ret. pass --force to re-run."1461 debug 2 "used cached result $ret. pass --force to re-run."
1448 return $ret;1462 return "$ret";
1449 fi1463 fi
1450 debug 1 "previous run returned unexpected '$ret'. Re-running."1464 debug 1 "previous run returned unexpected '$ret'. Re-running."
1451 else1465 else
@@ -1457,7 +1471,7 @@ main() {
1457 echo "$ret" > "$PATH_RUN_DI_RESULT"1471 echo "$ret" > "$PATH_RUN_DI_RESULT"
1458 read_uptime1472 read_uptime
1459 debug 1 "[up ${_RET}s]" "returning $ret"1473 debug 1 "[up ${_RET}s]" "returning $ret"
1460 return $ret1474 return "$ret"
1461}1475}
14621476
1463noop() {1477noop() {

Subscribers

People subscribed via source and target branches