diff options
author | Lyndon Brown <jnqnfe@gmail.com> | 2020-02-20 06:58:11 +0000 |
---|---|---|
committer | Lyndon Brown <jnqnfe@gmail.com> | 2020-03-16 22:10:03 +0000 |
commit | c55eb8a0c3ca5b8ed1081e7eb8a423563288fb58 (patch) | |
tree | 6ea61f7291b27ce9e22b40c5593c6ab6f54555d2 /functions/chroot.sh | |
parent | af040d78035b88aaf2f99f38bf5f0db176c92d0a (diff) | |
download | vyos-live-build-c55eb8a0c3ca5b8ed1081e7eb8a423563288fb58.tar.gz vyos-live-build-c55eb8a0c3ca5b8ed1081e7eb8a423563288fb58.zip |
use local scope for private function vars
all vars affected have been carefully checked to be quite certain
that they are definitely local
where variable is assigned the return value of a function/command, the
local "declaration" is deliberately done on a separate line, since
`local FOO` is actually treated itself as a command rather than a
declaration; will thus always cause $? to be zero, and thus if done on
the same line as such an assignment can not only clobber $? but in doing
so unintentionally blocks failure of a command from triggering the
expected exit from having `set -e`.
also, from testing, i have found that when assigning "${@}" this must be
done on a separate line confusingly as otherwise an error occurs.
Gbp-Dch: Short
Diffstat (limited to 'functions/chroot.sh')
-rwxr-xr-x | functions/chroot.sh | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/functions/chroot.sh b/functions/chroot.sh index 374cefd89..5658807e3 100755 --- a/functions/chroot.sh +++ b/functions/chroot.sh @@ -11,14 +11,16 @@ Chroot () { - CHROOT="${1}"; shift - COMMANDS="${@}" + local CHROOT="${1}"; shift + local COMMANDS + COMMANDS="${@}" #must be on separate line to 'local' declaration to avoid error # Executing commands in chroot Echo_debug "Executing: %s" "${COMMANDS}" ENV="" + local _FILE for _FILE in config/environment config/environment.chroot do if [ -e "${_FILE}" ] @@ -39,8 +41,8 @@ Chroot () } Chroot_has_package() { - PACKAGE="${1}"; shift - CHROOT="${2:-chroot}"; shift + local PACKAGE="${1}"; shift + local CHROOT="${2:-chroot}"; shift if dpkg-query --admindir=${CHROOT}/var/lib/dpkg -s ${PACKAGE} >/dev/null 2>&1 | grep -q "^Status: install" then @@ -50,7 +52,7 @@ Chroot_has_package() { } Chroot_package_list() { - CHROOT="${1:-chroot}"; shift + local CHROOT="${1:-chroot}"; shift dpkg-query --admindir=${CHROOT}/var/lib/dpkg -W -f'${Package}\n' } |