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 /scripts/build | |
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 'scripts/build')
-rwxr-xr-x | scripts/build/binary_grub-legacy | 21 | ||||
-rwxr-xr-x | scripts/build/binary_hdd | 2 | ||||
-rwxr-xr-x | scripts/build/binary_loopback_cfg | 10 | ||||
-rwxr-xr-x | scripts/build/config | 4 | ||||
-rwxr-xr-x | scripts/build/installer_debian-installer | 27 |
5 files changed, 33 insertions, 31 deletions
diff --git a/scripts/build/binary_grub-legacy b/scripts/build/binary_grub-legacy index 442b70326..fd54e7f64 100755 --- a/scripts/build/binary_grub-legacy +++ b/scripts/build/binary_grub-legacy @@ -50,10 +50,10 @@ Install_package # Local functions Grub_live_entry () { - LABEL="${1}" - KERNEL="${2}" - INITRD="${3}" - APPEND="${4}" + local LABEL="${1}" + local KERNEL="${2}" + local INITRD="${3}" + local APPEND="${4}" LINUX_LIVE="${LINUX_LIVE}\ntitle\t\tDebian GNU/Linux - ${LABEL}" LINUX_LIVE="${LINUX_LIVE}\nkernel\t\t/${KERNEL} ${INITFS:+boot=${INITFS} }config LB_BOOTAPPEND_LIVE ${APPEND}" @@ -62,15 +62,14 @@ Grub_live_entry () Grub_install_entry () { - LABEL="${1}" - KERNEL="${2}" - INITRD="${3}" - APPEND="${4}" + local LABEL="${1}" + local KERNEL="${2}" + local INITRD="${3}" + local APPEND="${4}" - APPEND="${APPEND} LB_BOOTAPPEND_INSTALL" + local APPEND="${APPEND} LB_BOOTAPPEND_INSTALL" - if [ "${LABEL}" != "expert" ] && [ "${LABEL}" != "expertgui" ] - then + if [ "${LABEL}" != "expert" ] && [ "${LABEL}" != "expertgui" ]; then APPEND="${APPEND} --- quiet" fi diff --git a/scripts/build/binary_hdd b/scripts/build/binary_hdd index a4d907fdd..bc9c61672 100755 --- a/scripts/build/binary_hdd +++ b/scripts/build/binary_hdd @@ -287,6 +287,8 @@ find /live/vmlinuz EOM EOF + local rootpartition + local hdddev rootpartition="$(Chroot chroot 'sh grub.sh' 2>/dev/null | grep -A 1 'find /live/vmlinuz' | grep -v 'find /live/vmlinuz')" hdddev="$(echo $rootpartition | sed -e 's|,[[:digit:]]||')" echo "Root partition is $rootpartition, device is: $hdddev" diff --git a/scripts/build/binary_loopback_cfg b/scripts/build/binary_loopback_cfg index 0b8af76a4..62681603a 100755 --- a/scripts/build/binary_loopback_cfg +++ b/scripts/build/binary_loopback_cfg @@ -66,11 +66,11 @@ Grub_live_entry () Grub_install_entry () { - LABEL="${1}" - TYPE="${2}" - KERNEL="${3}" - INITRD="${4}" - APPEND="${5}" + local LABEL="${1}" + local TYPE="${2}" + local KERNEL="${3}" + local INITRD="${4}" + local APPEND="${5}" # Drop "quiet" kernel parameter for expert entries case $TYPE in diff --git a/scripts/build/config b/scripts/build/config index 1d0c150ff..2b9ff701c 100755 --- a/scripts/build/config +++ b/scripts/build/config @@ -137,6 +137,7 @@ USAGE="${PROGRAM} [--apt apt|aptitude]\n\ Local_arguments () { + local LONG_OPTIONS LONG_OPTIONS="apt:,apt-ftp-proxy:,apt-http-proxy:,apt-options:,aptitude-options:,debootstrap-options:,debootstrap-script:, apt-pipeline:,apt-recommends:,apt-secure:,apt-source-archives:,cache:,cache-indices:,cache-packages:, cache-stages:,debconf-frontend:,debconf-priority:,dump, @@ -165,6 +166,7 @@ Local_arguments () # Remove spaces added by indentation LONG_OPTIONS="$(echo ${LONG_OPTIONS} | tr -d ' ')" + local ARGUMENTS local ERR=0 ARGUMENTS="$(getopt --longoptions ${LONG_OPTIONS} --name="${PROGRAM}" --options a:d:m:k:b:s:c:huv --shell sh -- "${@}")" || ERR=$? @@ -183,6 +185,7 @@ Local_arguments () case "${1}" in --dump) # Dump version + local VERSION_DPKG if [ $(which dpkg-query) ] then VERSION_DPKG="$(dpkg-query -f='${Version}' --show live-build)" @@ -194,6 +197,7 @@ Local_arguments () Print_conffiles $(Common_config_files) # Dump contents of directories that contain text files + local DIRECTORY for DIRECTORY in config/package-lists config/apt config/preseed config/rootfs do if Find_files "${DIRECTORY}" diff --git a/scripts/build/installer_debian-installer b/scripts/build/installer_debian-installer index 343c678ee..5eb935fe6 100755 --- a/scripts/build/installer_debian-installer +++ b/scripts/build/installer_debian-installer @@ -151,8 +151,7 @@ case "${LB_ARCHITECTURES}" in esac Install_file() { - local FILE - FILE="${1}" + local FILE="${1}" Echo_debug "Installing file %s" "${FILE}" @@ -166,9 +165,9 @@ Install_file() { ARCHIVE_AREA="main" fi - local TARGET - TARGET="${2}/${ARCHIVE_AREA}" + local TARGET="${2}/${ARCHIVE_AREA}" + local SOURCE SOURCE="$(dpkg -f ${FILE} Source | awk '{ print $1 }')" if [ -z "${SOURCE}" ] @@ -176,6 +175,7 @@ Install_file() { SOURCE="$(basename ${FILE} | awk -F_ '{ print $1 }')" fi + local LETTER case "${SOURCE}" in lib?*) LETTER="$(echo ${SOURCE} | sed 's|\(....\).*|\1|')" @@ -198,14 +198,12 @@ Install_file() { _LB_CACHE_DIR="$(pwd)/cache/installer_debian-installer" Download_file () { - local _LB_TARGET - _LB_TARGET="${1}" - - local _LB_URL - _LB_URL="${2}" + local _LB_TARGET="${1}" + local _LB_URL="${2}" Echo_debug "Downloading file \`%s\` from \`%s\`" "${_LB_TARGET}" "${_LB_URL}" + local _LB_CACHE_FILE _LB_CACHE_FILE="${_LB_CACHE_DIR}/$(echo "${_LB_URL}" | sed 's|/|_|g')" if [ ! -f "${_LB_CACHE_FILE}" ] @@ -795,11 +793,9 @@ fi Repack_initrd() { - local TARGET_INITRD - local INCLUDE_PATH - TARGET_INITRD="${1}" - INCLUDE_PATH="${2}" - REPACK_TMPDIR="unpacked-initrd" + local TARGET_INITRD="${1}" + local INCLUDE_PATH="${2}" + local REPACK_TMPDIR="unpacked-initrd" Echo_debug "Repacking initrd \`%s\`" "${TARGET_INITRD}" @@ -816,6 +812,7 @@ Repack_initrd() if [ ! -d "${INCLUDE_PATH}" ] then # Invoked the old way, just copy the preseeds + local _FILE for _FILE in ../config/preseed/*.cfg ../config/preseed/*.cfg.installer do if [ -e "${_FILE}" ] @@ -825,7 +822,7 @@ Repack_initrd() done else # New way, include target directory content in the initrd - REPACK_TMPDIR_ABS="${PWD}" + local REPACK_TMPDIR_ABS="${PWD}" cd "${INCLUDE_PATH}" find -print0 | cpio -pumd0 --no-preserve-owner "${REPACK_TMPDIR_ABS}/" cd "${OLDPWD}" |