From 1b69d037acab1f44ae0d10938d907c0231c154c5 Mon Sep 17 00:00:00 2001 From: Matthias Stecher Date: Sun, 5 Jul 2020 20:50:40 +0200 Subject: [PATCH] [__lxc_container] fix some shellchecks (incl. warnings) To the error in the `explorer/state`: It's intended, as it passes possible parameters to the command. Varibale will set unquoted, so word splitting take action, but the quotes inside the variable work. --- cdist/conf/type/__lxc_container/explorer/state | 2 ++ cdist/conf/type/__lxc_container/gencode-remote | 6 +++--- cdist/conf/type/__lxc_container/manifest | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cdist/conf/type/__lxc_container/explorer/state b/cdist/conf/type/__lxc_container/explorer/state index fc37edf7..c3c7f30f 100755 --- a/cdist/conf/type/__lxc_container/explorer/state +++ b/cdist/conf/type/__lxc_container/explorer/state @@ -19,12 +19,14 @@ lxcpath="$(cat "$__object/parameter/lxcpath" 2>/dev/null || true)" # assemble optional parameters LXC_PARAM="" if [ "$lxcpath" ]; then + # shellcheck disable=SC2089 LXC_PARAM="$LXC_PARAM -P \"$lxcpath\"" fi # function to get information lxc_info() { + # shellcheck disable=SC2090 disable=SC2086 if [ "$user" != "$USER" ]; then su -s "$(which -- lxc-info)" -- "$user" $LXC_PARAM -n "$name" -H "$@" else diff --git a/cdist/conf/type/__lxc_container/gencode-remote b/cdist/conf/type/__lxc_container/gencode-remote index ef61c66d..2177e377 100755 --- a/cdist/conf/type/__lxc_container/gencode-remote +++ b/cdist/conf/type/__lxc_container/gencode-remote @@ -44,7 +44,7 @@ fi # shortcut for checking config changes tmppath="$__object/files/remote-tmpfile" config_changes() { - if ( [ -f "${tmppath}_add" ] || [ -f "${tmppath}_del" ] ); then + if [ -f "${tmppath}_add" ] || [ -f "${tmppath}_del" ]; then return 0 else return 1 @@ -91,7 +91,7 @@ USER backingstore_opts="" if [ -f "$__object/parameter/backingstore" ]; then # -B works for both types, they have different long opts - backingstore_opts="-B '$(cat "$__object/parameter/backingstore")'" + backingstore_opts="$backingstore_opts -B '$(cat "$__object/parameter/backingstore")'" # add parameters if available bdev_add_if_available dir @@ -149,7 +149,7 @@ LXC # at last, apply custom options if [ -f "$__object/parameter/template-opts" ]; then - while read line; do + while read -r line; do template_opts="$template_opts $line" done < "$__object/parameter/template-opts" fi diff --git a/cdist/conf/type/__lxc_container/manifest b/cdist/conf/type/__lxc_container/manifest index d903fa1c..4a74ea18 100755 --- a/cdist/conf/type/__lxc_container/manifest +++ b/cdist/conf/type/__lxc_container/manifest @@ -93,7 +93,7 @@ fi write_multi_param() { if ! [ -f "$__object/parameter/$1" ]; then return 0; fi - while read line; do + while read -r line; do if [ "$line" = "-" ]; then # append stdin cat "$__object/stdin"