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/main.bash | 2 ++ lib/subcommands/add.bash | 5 ++++- lib/subcommands/bootstrap.bash | 4 ++-- lib/subcommands/del.bash | 5 ++++- lib/subcommands/ssh.bash | 5 +++-- lib/subcommands/sync.bash | 8 +++++--- lib/util.bash | 30 +++++++++++++++++++++--------- 7 files changed, 41 insertions(+), 18 deletions(-) (limited to 'lib') diff --git a/lib/main.bash b/lib/main.bash index 227512a..656f5c6 100644 --- a/lib/main.bash +++ b/lib/main.bash @@ -174,6 +174,8 @@ discover_system_version() { } discover_system_key() { + local key + key+="${BASHTARD_PLATFORM[os]}" if [[ ${BASHTARD_PLATFORM[distro]} ]] diff --git a/lib/subcommands/add.bash b/lib/subcommands/add.bash index 590c8ec..c72582b 100644 --- a/lib/subcommands/add.bash +++ b/lib/subcommands/add.bash @@ -6,6 +6,8 @@ subcommand() { + local buffer + export BASHTARD_PLAYBOOK="$1" ; shift if [[ -z "$BASHTARD_PLAYBOOK" ]] @@ -38,6 +40,7 @@ subcommand() return 1 fi + # shellcheck disable=SC1090 . "$playbook_base/playbook.bash" if ! playbook_add @@ -46,7 +49,7 @@ subcommand() return 1 fi - local buffer="$(tmpfile)" + buffer="$(tmpfile)" # Add the playbook to the registry cp -- "$playbook_registry" "$buffer" diff --git a/lib/subcommands/bootstrap.bash b/lib/subcommands/bootstrap.bash index 343547d..a457a2f 100644 --- a/lib/subcommands/bootstrap.bash +++ b/lib/subcommands/bootstrap.bash @@ -15,7 +15,7 @@ subcommand() return fi - bootstrap_remote + bootstrap_remote "$@" } bootstrap_local() @@ -69,7 +69,7 @@ bootstrap_remote() touch -- "$file" done - while read -r playbook url branch + while read -r playbook url _ do notice "bashtard/bootstrap" "Cloning $playbook from $url" git clone "$url" "$BASHTARD_ETCDIR/playbooks.d/$playbook" diff --git a/lib/subcommands/del.bash b/lib/subcommands/del.bash index 9f01c3c..f5204d8 100644 --- a/lib/subcommands/del.bash +++ b/lib/subcommands/del.bash @@ -6,6 +6,8 @@ subcommand() { + local buffer + export BASHTARD_PLAYBOOK="$1" ; shift if [[ -z "$BASHTARD_PLAYBOOK" ]] @@ -38,6 +40,7 @@ subcommand() return 1 fi + # shellcheck disable=SC1090 . "$playbook_base/playbook.bash" if ! playbook_del @@ -46,7 +49,7 @@ subcommand() return 1 fi - local buffer="$(tmpfile)" + buffer="$(tmpfile)" # Remove the playbook from the registry cp -- "$playbook_registry" "$buffer" diff --git a/lib/subcommands/ssh.bash b/lib/subcommands/ssh.bash index 0eb4be8..b5712cc 100644 --- a/lib/subcommands/ssh.bash +++ b/lib/subcommands/ssh.bash @@ -6,7 +6,9 @@ subcommand() { - local ssh="$(config app.ssh)" + local ssh + + ssh="$(config "app.ssh")" if [[ ! -d "$BASHTARD_ETCDIR/hosts.d" ]] then @@ -20,7 +22,6 @@ subcommand() do local user local host - local ip user="$(config_for "$node" "ssh.user" "root")" diff --git a/lib/subcommands/sync.bash b/lib/subcommands/sync.bash index 7722e2d..0ec2ffc 100644 --- a/lib/subcommands/sync.bash +++ b/lib/subcommands/sync.bash @@ -9,7 +9,7 @@ subcommand() export BASHTARD_PLAYBOOK="$1" ; shift # If a specific playbook is given, sync that - if [[ ! -z "$BASHTARD_PLAYBOOK" ]] + if [[ -n "$BASHTARD_PLAYBOOK" ]] then sync_playbook "$BASHTARD_PLAYBOOK" return @@ -19,9 +19,10 @@ subcommand() notice "bashtard/sync" "Syncing remote playbooks" # Update all playbook sources - while read -r playbook url branch + while read -r playbook _ branch do - pushd -- "$BASHTARD_ETCDIR/playbooks.d/$playbook" + pushd -- "$BASHTARD_ETCDIR/playbooks.d/$playbook" \ + || return 2 git pull origin "$branch" done < "$BASHTARD_ETCDIR/playbooks.d/remotes" @@ -51,6 +52,7 @@ sync_playbook() return 1 fi + # shellcheck disable=SC1090 . "$playbook_base/playbook.bash" playbook_sync 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