From fba67928920f3b1e6d10123de9a7efae0dac177f Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Sun, 17 Apr 2022 22:56:59 +0200 Subject: Make shellcheck happy --- lib/util.bash | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'lib/util.bash') diff --git a/lib/util.bash b/lib/util.bash index ea9ac3b..79bac92 100644 --- a/lib/util.bash +++ b/lib/util.bash @@ -32,7 +32,7 @@ config_for() { "$BASHTARD_ETCDIR/defaults" ) - if [[ ! -z "$BASHTARD_PLAYBOOK" ]] + if [[ -n "$BASHTARD_PLAYBOOK" ]] then debug "bashtard/config_for" "BASHTARD_PLAYBOOK=$BASHTARD_PLAYBOOK, adding etc entries" files+=( @@ -189,9 +189,10 @@ join_args() { # OS independent package management pkg() { local system="bashtard/pkg" - local action=$1 ; shift - local pkg="$(config "pkg.$1")" ; shift + local pkg + + pkg="$(config "pkg.$1")" ; shift if [[ -z $pkg ]] then @@ -199,7 +200,7 @@ pkg() { return 1 fi - if [[ "$(type -t pkg_$action)" != "function" ]] + if [[ "$(type -t "pkg_$action")" != "function" ]] then crit "$system" "Invalid package manager action $action" return 1 @@ -224,6 +225,7 @@ pkg_install() { esac notice "$system" "$*" + # shellcheck disable=SC2068 $@ } @@ -243,6 +245,7 @@ pkg_uninstall() { esac notice "$system" "$*" + # shellcheck disable=SC2068 $@ } @@ -254,7 +257,7 @@ svc() { local action action=$1 ; shift - service="$(config svc.$1)" ; shift + service="$(config "svc.$1")" ; shift if [[ -z $service ]] then @@ -262,7 +265,7 @@ svc() { return 1 fi - if [[ "$(type -t svc_$action)" != "function" ]] + if [[ "$(type -t "svc_$action")" != "function" ]] then crit "$system" "Invalid service manager action $action" return 1 @@ -285,6 +288,7 @@ svc_disable() { esac notice "$system" "$*" + # shellcheck disable=SC2068 $@ } @@ -302,6 +306,7 @@ svc_enable() { esac notice "$system" "$*" + # shellcheck disable=SC2068 $@ } @@ -320,6 +325,7 @@ svc_reload() { esac notice "$system" "$*" + # shellcheck disable=SC2068 $@ } @@ -338,6 +344,7 @@ svc_restart() { esac notice "$system" "$*" + # shellcheck disable=SC2068 $@ } @@ -356,6 +363,7 @@ svc_start() { esac notice "$system" "$*" + # shellcheck disable=SC2068 $@ } @@ -374,13 +382,16 @@ svc_stop() { esac notice "$system" "$*" + # shellcheck disable=SC2068 $@ } file_template() { local file="$BASHTARD_ETCDIR/playbooks.d/$BASHTARD_PLAYBOOK/share/$1" ; shift - local sedfile="$(tmpfile)" + local sedfile + + sedfile="$(tmpfile)" if [[ ! -f $file ]] then @@ -392,20 +403,21 @@ file_template() do debug "bashtard/template" "Adding $kv to sedfile at $sedfile" - key="$(awk -F= '{ print $1 }' <<< $kv)" + key="$(awk -F= '{ print $1 }' <<< "$kv")" if [[ -z "$key" ]] then crit "bashtard/template" "Empty key in '$kv' while rendering $file?" fi - value="$(awk -F= '{ print $NF }' <<< $kv)" + value="$(awk -F= '{ print $NF }' <<< "$kv")" if [[ -z "$value" ]] then crit "bashtard/template" "Empty key in '$kv' while rendering $file?" fi + # shellcheck disable=SC2016 printf 's@${%s}@%s@g\n' "$key" "$value" >> "$sedfile" done -- cgit v1.1