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
This commit is contained in:
Lyndon Brown 2020-02-20 06:58:11 +00:00
parent af040d7803
commit c55eb8a0c3
23 changed files with 141 additions and 84 deletions

View File

@ -19,6 +19,7 @@ In_list ()
local NEEDLE="${1}" local NEEDLE="${1}"
shift shift
local ITEM
for ITEM in ${@} for ITEM in ${@}
do do
if [ "${NEEDLE}" = "${ITEM}" ] if [ "${NEEDLE}" = "${ITEM}" ]
@ -32,6 +33,7 @@ In_list ()
Truncate () Truncate ()
{ {
local FILE
for FILE in ${@} for FILE in ${@}
do do
if [ ! -L ${FILE} ] if [ ! -L ${FILE} ]

View File

@ -11,9 +11,11 @@
Check_architectures () Check_architectures ()
{ {
ARCHITECTURES="${@}" local ARCHITECTURES
VALID=false ARCHITECTURES="${@}" #must be on separate line to 'local' declaration to avoid error
local VALID=false
local ARCHITECTURE
for ARCHITECTURE in ${ARCHITECTURES} for ARCHITECTURE in ${ARCHITECTURES}
do do
if [ "$(echo ${LB_ARCHITECTURES} | grep ${ARCHITECTURE})" ] if [ "$(echo ${LB_ARCHITECTURES} | grep ${ARCHITECTURE})" ]
@ -50,6 +52,7 @@ Check_architectures ()
Check_crossarchitectures () Check_crossarchitectures ()
{ {
local HOST
if [ $(which dpkg) ] if [ $(which dpkg) ]
then then
HOST="$(dpkg --print-architecture)" HOST="$(dpkg --print-architecture)"
@ -57,6 +60,7 @@ Check_crossarchitectures ()
HOST="$(uname -m)" HOST="$(uname -m)"
fi fi
local CROSS
case "${HOST}" in case "${HOST}" in
amd64|i386|x86_64) amd64|i386|x86_64)
CROSS="amd64 i386" CROSS="amd64 i386"

View File

@ -11,6 +11,7 @@
Arguments () Arguments ()
{ {
local ARGUMENTS
local ERR=0 local ERR=0
ARGUMENTS="$(getopt --longoptions breakpoints,color,no-color,conffile:,debug,force,help,quiet,usage,verbose,version --name=${PROGRAM} --options c:huv --shell sh -- "${@}")" || ERR=$? ARGUMENTS="$(getopt --longoptions breakpoints,color,no-color,conffile:,debug,force,help,quiet,usage,verbose,version --name=${PROGRAM} --options c:huv --shell sh -- "${@}")" || ERR=$?

View File

@ -10,8 +10,9 @@
Is_Requested_Bootloader () Is_Requested_Bootloader ()
{ {
OLDIFS="$IFS" local OLDIFS="$IFS"
IFS="," local IFS=","
local BOOTLOADER
for BOOTLOADER in ${LB_BOOTLOADERS}; do for BOOTLOADER in ${LB_BOOTLOADERS}; do
if [ "${BOOTLOADER}" = "${1}" ]; then if [ "${BOOTLOADER}" = "${1}" ]; then
IFS="$OLDIFS" IFS="$OLDIFS"

View File

@ -11,7 +11,7 @@
Breakpoint () Breakpoint ()
{ {
NAME="${1}" local NAME="${1}"
if [ "${_BREAKPOINTS}" = "true" ] if [ "${_BREAKPOINTS}" = "true" ]
then then

View File

@ -11,7 +11,7 @@
Restore_package_cache () Restore_package_cache ()
{ {
DIRECTORY="cache/packages.${1}" local DIRECTORY="cache/packages.${1}"
if [ "${LB_CACHE}" = "true" ] && [ "${LB_CACHE_PACKAGES}" = "true" ] if [ "${LB_CACHE}" = "true" ] && [ "${LB_CACHE_PACKAGES}" = "true" ]
then then
@ -32,7 +32,7 @@ Restore_package_cache ()
Save_package_cache () Save_package_cache ()
{ {
DIRECTORY="cache/packages.${1}" local DIRECTORY="cache/packages.${1}"
if [ "${LB_CACHE}" = "true" ] && [ "${LB_CACHE_PACKAGES}" = "true" ] if [ "${LB_CACHE}" = "true" ] && [ "${LB_CACHE_PACKAGES}" = "true" ]
then then
@ -47,6 +47,7 @@ Save_package_cache ()
mkdir -p "${DIRECTORY}" mkdir -p "${DIRECTORY}"
# Saving new cache # Saving new cache
local PACKAGE
for PACKAGE in chroot/var/cache/apt/archives/*.deb for PACKAGE in chroot/var/cache/apt/archives/*.deb
do do
if [ -e "${DIRECTORY}"/"$(basename ${PACKAGE})" ] if [ -e "${DIRECTORY}"/"$(basename ${PACKAGE})" ]

View File

@ -11,14 +11,16 @@
Chroot () Chroot ()
{ {
CHROOT="${1}"; shift local CHROOT="${1}"; shift
COMMANDS="${@}" local COMMANDS
COMMANDS="${@}" #must be on separate line to 'local' declaration to avoid error
# Executing commands in chroot # Executing commands in chroot
Echo_debug "Executing: %s" "${COMMANDS}" Echo_debug "Executing: %s" "${COMMANDS}"
ENV="" ENV=""
local _FILE
for _FILE in config/environment config/environment.chroot for _FILE in config/environment config/environment.chroot
do do
if [ -e "${_FILE}" ] if [ -e "${_FILE}" ]
@ -39,8 +41,8 @@ Chroot ()
} }
Chroot_has_package() { Chroot_has_package() {
PACKAGE="${1}"; shift local PACKAGE="${1}"; shift
CHROOT="${2:-chroot}"; shift local CHROOT="${2:-chroot}"; shift
if dpkg-query --admindir=${CHROOT}/var/lib/dpkg -s ${PACKAGE} >/dev/null 2>&1 | grep -q "^Status: install" if dpkg-query --admindir=${CHROOT}/var/lib/dpkg -s ${PACKAGE} >/dev/null 2>&1 | grep -q "^Status: install"
then then
@ -50,7 +52,7 @@ Chroot_has_package() {
} }
Chroot_package_list() { Chroot_package_list() {
CHROOT="${1:-chroot}"; shift local CHROOT="${1:-chroot}"; shift
dpkg-query --admindir=${CHROOT}/var/lib/dpkg -W -f'${Package}\n' dpkg-query --admindir=${CHROOT}/var/lib/dpkg -W -f'${Package}\n'
} }

View File

@ -11,6 +11,9 @@
Chroot_bind_path () Chroot_bind_path ()
{ {
local CHROOT
local BIND_SRC
local BIND_DEST
CHROOT="$(readlink -f ${1})" CHROOT="$(readlink -f ${1})"
BIND_SRC="$(readlink -f ${2})" BIND_SRC="$(readlink -f ${2})"
@ -27,6 +30,9 @@ Chroot_bind_path ()
Chroot_unbind_path () Chroot_unbind_path ()
{ {
local CHROOT
local BIND_SRC
local BIND_DEST
CHROOT="$(readlink -f ${1})" CHROOT="$(readlink -f ${1})"
BIND_SRC="$(readlink -f ${2})" BIND_SRC="$(readlink -f ${2})"

View File

@ -11,10 +11,12 @@
Get_conffiles () Get_conffiles ()
{ {
local FILES
if [ -n "${LB_CONFIG}" ] if [ -n "${LB_CONFIG}" ]
then then
FILES="${LB_CONFIG}" FILES="${LB_CONFIG}"
else else
local FILE
for FILE in ${@} for FILE in ${@}
do do
FILES="${FILES} ${FILE} ${FILE}.${LB_ARCHITECTURES} ${FILE}.${DISTRIBUTION}" FILES="${FILES} ${FILE} ${FILE}.${LB_ARCHITECTURES} ${FILE}.${DISTRIBUTION}"
@ -29,6 +31,7 @@ Get_conffiles ()
Read_conffiles () Read_conffiles ()
{ {
local CONFFILE
for CONFFILE in $(Get_conffiles "${@}") for CONFFILE in $(Get_conffiles "${@}")
do do
if [ -f "${CONFFILE}" ] if [ -f "${CONFFILE}" ]
@ -46,6 +49,7 @@ Read_conffiles ()
Print_conffiles () Print_conffiles ()
{ {
local CONFFILE
for CONFFILE in $(Get_conffiles "${@}") for CONFFILE in $(Get_conffiles "${@}")
do do
if [ -f "${CONFFILE}" ] if [ -f "${CONFFILE}" ]

View File

@ -11,29 +11,30 @@
Get_configuration () Get_configuration ()
{ {
_CONFIGURATION_FILE="${1}" local CONFIGURATION_FILE="${1}"
_FIELD_NAME="${2}" local FIELD_NAME="${2}"
local FIELD_BODY
if [ -e "${_CONFIGURATION_FILE}" ] if [ -e "${CONFIGURATION_FILE}" ]
then then
_FIELD_BODY="$(grep ^${_FIELD_NAME}: ${_CONFIGURATION_FILE} | awk '{ $1=""; print $0 }' | sed -e 's|^ ||')" FIELD_BODY="$(grep ^${FIELD_NAME}: ${CONFIGURATION_FILE} | awk '{ $1=""; print $0 }' | sed -e 's|^ ||')"
fi fi
echo ${_FIELD_BODY} echo ${FIELD_BODY}
} }
Set_configuration () Set_configuration ()
{ {
_CONFIGURATION_FILE="${1}" local CONFIGURATION_FILE="${1}"
_FIELD_NAME="${2}" local FIELD_NAME="${2}"
_FIELD_BODY="${3}" local FIELD_BODY="${3}"
if grep -qs "^${_FIELD_NAME}:" "${_CONFIGURATION_FILE}" if grep -qs "^${FIELD_NAME}:" "${CONFIGURATION_FILE}"
then then
# Update configuration # Update configuration
sed -i -e "s|^${_FIELD_NAME}:.*$|${_FIELD_NAME}: ${_FIELD_BODY}|" "${_CONFIGURATION_FILE}" sed -i -e "s|^${FIELD_NAME}:.*$|${FIELD_NAME}: ${FIELD_BODY}|" "${CONFIGURATION_FILE}"
else else
# Append configuration # Append configuration
echo "${_FIELD_NAME}: ${_FIELD_BODY}" >> "${_CONFIGURATION_FILE}" echo "${FIELD_NAME}: ${FIELD_BODY}" >> "${CONFIGURATION_FILE}"
fi fi
} }

View File

@ -96,6 +96,7 @@ Set_config_defaults ()
# Setting mode (currently: debian, progress-linux) # Setting mode (currently: debian, progress-linux)
if [ $(which lsb_release) ] if [ $(which lsb_release) ]
then then
local _DISTRIBUTOR
_DISTRIBUTOR="$(lsb_release -is | tr "[A-Z]" "[a-z]")" _DISTRIBUTOR="$(lsb_release -is | tr "[A-Z]" "[a-z]")"
case "${_DISTRIBUTOR}" in case "${_DISTRIBUTOR}" in
@ -624,6 +625,7 @@ Set_config_defaults ()
;; ;;
esac esac
local _LB_BOOTAPPEND_PRESEED
if [ -n "${LB_DEBIAN_INSTALLER_PRESEEDFILE}" ] if [ -n "${LB_DEBIAN_INSTALLER_PRESEEDFILE}" ]
then then
case "${LIVE_IMAGE_TYPE}" in case "${LIVE_IMAGE_TYPE}" in

View File

@ -12,7 +12,7 @@ exec 3>&1
Echo () Echo ()
{ {
STRING="${1}" local STRING="${1}"
shift shift
printf "${STRING}\n" "${@}" >&3 printf "${STRING}\n" "${@}" >&3
@ -21,7 +21,7 @@ Echo ()
Echo_debug () Echo_debug ()
{ {
if [ "${_DEBUG}" = "true" ]; then if [ "${_DEBUG}" = "true" ]; then
STRING="${1}" local STRING="${1}"
shift shift
printf "D: ${STRING}\n" "${@}" >&3 printf "D: ${STRING}\n" "${@}" >&3
@ -30,7 +30,7 @@ Echo_debug ()
Echo_error () Echo_error ()
{ {
STRING="${1}" local STRING="${1}"
shift shift
local PREFIX="${RED}E${NO_COLOR}" local PREFIX="${RED}E${NO_COLOR}"
@ -45,7 +45,7 @@ Echo_message ()
{ {
if [ "${_QUIET}" != "true" ] if [ "${_QUIET}" != "true" ]
then then
STRING="${1}" local STRING="${1}"
shift shift
local PREFIX="${PURPLE}P${NO_COLOR}" local PREFIX="${PURPLE}P${NO_COLOR}"
@ -60,7 +60,7 @@ Echo_message ()
Echo_verbose () Echo_verbose ()
{ {
if [ "${_VERBOSE}" = "true" ]; then if [ "${_VERBOSE}" = "true" ]; then
STRING="${1}" local STRING="${1}"
shift shift
printf "I: ${STRING}\n" "${@}" >&3 printf "I: ${STRING}\n" "${@}" >&3
@ -69,7 +69,7 @@ Echo_verbose ()
Echo_warning () Echo_warning ()
{ {
STRING="${1}" local STRING="${1}"
shift shift
local PREFIX="${YELLOW}W${NO_COLOR}" local PREFIX="${YELLOW}W${NO_COLOR}"
@ -82,6 +82,7 @@ Echo_warning ()
Echo_file () Echo_file ()
{ {
local LINE
while read -r LINE while read -r LINE
do do
echo "${1}: ${LINE}" >&3 echo "${1}: ${LINE}" >&3

View File

@ -19,6 +19,7 @@ Firmware_List_From_Contents () {
local DISTRO_CHROOT="${2}" local DISTRO_CHROOT="${2}"
local ARCHIVE_AREAS="${3}" local ARCHIVE_AREAS="${3}"
local _ARCHIVE_AREA
for _ARCHIVE_AREA in ${ARCHIVE_AREAS} for _ARCHIVE_AREA in ${ARCHIVE_AREAS}
do do
local CONTENTS_URL="${MIRROR_CHROOT}/dists/${DISTRO_CHROOT}/${_ARCHIVE_AREA}/Contents-${LB_ARCHITECTURES}.gz" local CONTENTS_URL="${MIRROR_CHROOT}/dists/${DISTRO_CHROOT}/${_ARCHIVE_AREA}/Contents-${LB_ARCHITECTURES}.gz"

View File

@ -10,8 +10,8 @@
Lodetach () Lodetach ()
{ {
DEVICE="${1}" local DEVICE="${1}"
ATTEMPT="${2:-1}" local ATTEMPT="${2:-1}"
if [ "${ATTEMPT}" -gt 3 ] if [ "${ATTEMPT}" -gt 3 ]
then then
@ -37,10 +37,12 @@ Lodetach ()
Losetup () Losetup ()
{ {
DEVICE="${1}" local DEVICE="${1}"
FILE="${2}" local FILE="${2}"
PARTITION="${3:-1}" local PARTITION="${3:-1}"
local FDISK_OUT
local LOOPDEVICE
losetup --read-only --partscan "${DEVICE}" "${FILE}" losetup --read-only --partscan "${DEVICE}" "${FILE}"
FDISK_OUT="$(fdisk -l -u ${DEVICE} 2>&1)" FDISK_OUT="$(fdisk -l -u ${DEVICE} 2>&1)"
Lodetach "${DEVICE}" Lodetach "${DEVICE}"
@ -53,6 +55,8 @@ Losetup ()
losetup --partscan "${DEVICE}" "${FILE}" losetup --partscan "${DEVICE}" "${FILE}"
else else
local SECTORS
local OFFSET
SECTORS="$(echo "$FDISK_OUT" | sed -ne "s|^$LOOPDEVICE[ *]*\([0-9]*\).*|\1|p")" SECTORS="$(echo "$FDISK_OUT" | sed -ne "s|^$LOOPDEVICE[ *]*\([0-9]*\).*|\1|p")"
OFFSET="$(expr ${SECTORS} '*' 512)" OFFSET="$(expr ${SECTORS} '*' 512)"
@ -65,7 +69,7 @@ Losetup ()
# adapted from lib/ext2fs/mkjournal.c, default block size is 4096 bytes (/etc/mke2fs.conf). # adapted from lib/ext2fs/mkjournal.c, default block size is 4096 bytes (/etc/mke2fs.conf).
ext2fs_default_journal_size() ext2fs_default_journal_size()
{ {
SIZE="$1" local SIZE="$1"
if [ "${SIZE}" -lt "8" ]; then # 2048*4096 if [ "${SIZE}" -lt "8" ]; then # 2048*4096
echo 0 echo 0
elif [ "${SIZE}" -lt "128" ]; then # 32768*4096 elif [ "${SIZE}" -lt "128" ]; then # 32768*4096
@ -83,9 +87,10 @@ ext2fs_default_journal_size()
Calculate_partition_size_without_journal () Calculate_partition_size_without_journal ()
{ {
WITHOUT_JOURNAL_ORIGINAL_SIZE="${1}" local WITHOUT_JOURNAL_ORIGINAL_SIZE="${1}"
WITHOUT_JOURNAL_FILESYSTEM="${2}" local WITHOUT_JOURNAL_FILESYSTEM="${2}"
local PERCENT
case "${WITHOUT_JOURNAL_FILESYSTEM}" in case "${WITHOUT_JOURNAL_FILESYSTEM}" in
ext2|ext3|ext4) ext2|ext3|ext4)
PERCENT="6" PERCENT="6"
@ -100,11 +105,16 @@ Calculate_partition_size_without_journal ()
Calculate_partition_size () Calculate_partition_size ()
{ {
ORIGINAL_SIZE="${1}" local ORIGINAL_SIZE="${1}"
FILESYSTEM="${2}" local FILESYSTEM="${2}"
case "${FILESYSTEM}" in case "${FILESYSTEM}" in
ext3|ext4) ext3|ext4)
local NON_JOURNAL_SIZE
local PROJECTED_JOURNAL_SIZE
local PROJECTED_PARTITION_SIZE
local PRE_FINAL_PARTITION_SIZE
local JOURNAL_SIZE
NON_JOURNAL_SIZE=$(Calculate_partition_size_without_journal ${ORIGINAL_SIZE} ${FILESYSTEM}) NON_JOURNAL_SIZE=$(Calculate_partition_size_without_journal ${ORIGINAL_SIZE} ${FILESYSTEM})
PROJECTED_JOURNAL_SIZE=$(ext2fs_default_journal_size ${NON_JOURNAL_SIZE}) PROJECTED_JOURNAL_SIZE=$(ext2fs_default_journal_size ${NON_JOURNAL_SIZE})
PROJECTED_PARTITION_SIZE=$(expr ${ORIGINAL_SIZE} + ${PROJECTED_JOURNAL_SIZE}) PROJECTED_PARTITION_SIZE=$(expr ${ORIGINAL_SIZE} + ${PROJECTED_JOURNAL_SIZE})

View File

@ -11,17 +11,20 @@
Expand_packagelist () Expand_packagelist ()
{ {
local _LB_EXPAND_QUEUE
_LB_EXPAND_QUEUE="$(basename "${1}")" _LB_EXPAND_QUEUE="$(basename "${1}")"
shift shift
while [ -n "${_LB_EXPAND_QUEUE}" ] while [ -n "${_LB_EXPAND_QUEUE}" ]
do do
local _LB_LIST_NAME
local _LB_EXPAND_QUEUE
_LB_LIST_NAME="$(echo ${_LB_EXPAND_QUEUE} | cut -d" " -f1)" _LB_LIST_NAME="$(echo ${_LB_EXPAND_QUEUE} | cut -d" " -f1)"
_LB_EXPAND_QUEUE="$(echo ${_LB_EXPAND_QUEUE} | cut -s -d" " -f2-)" _LB_EXPAND_QUEUE="$(echo ${_LB_EXPAND_QUEUE} | cut -s -d" " -f2-)"
_LB_LIST_LOCATION="" local _LB_LIST_LOCATION=""
_LB_NESTED=0 local _LB_NESTED=0
_LB_ENABLED=1 local _LB_ENABLED=1
for _LB_SEARCH_PATH in ${@} for _LB_SEARCH_PATH in ${@}
do do
@ -42,6 +45,7 @@ Expand_packagelist ()
do do
case "${_LB_LINE}" in case "${_LB_LINE}" in
\!*) \!*)
local _EXEC
_EXEC="$(echo ${_LB_LINE} | sed -e 's|^!||')" _EXEC="$(echo ${_LB_LINE} | sed -e 's|^!||')"
case "${LB_BUILD_WITH_CHROOT}" in case "${LB_BUILD_WITH_CHROOT}" in
@ -63,6 +67,10 @@ Expand_packagelist ()
fi fi
_LB_NESTED=1 _LB_NESTED=1
local _LB_NEEDLE
local _LB_HAYSTACK
local _LB_NEEDLE_PART
local _LB_HAYSTACK_PART
_LB_NEEDLE="$(echo "${_LB_LINE}" | cut -d' ' -f3-)" _LB_NEEDLE="$(echo "${_LB_LINE}" | cut -d' ' -f3-)"
_LB_HAYSTACK="$(eval "echo \$LB_$(echo "${_LB_LINE}" | cut -d' ' -f2)")" _LB_HAYSTACK="$(eval "echo \$LB_$(echo "${_LB_LINE}" | cut -d' ' -f2)")"
@ -87,6 +95,10 @@ Expand_packagelist ()
fi fi
_LB_NESTED=1 _LB_NESTED=1
local _LB_NEEDLE
local _LB_HAYSTACK
local _LB_NEEDLE_PART
local _LB_HAYSTACK_PART
_LB_NEEDLE="$(echo "${_LB_LINE}" | cut -d' ' -f3-)" _LB_NEEDLE="$(echo "${_LB_LINE}" | cut -d' ' -f3-)"
_LB_HAYSTACK="$(eval "echo \$LB_$(echo "${_LB_LINE}" | cut -d' ' -f2)")" _LB_HAYSTACK="$(eval "echo \$LB_$(echo "${_LB_LINE}" | cut -d' ' -f2)")"
@ -126,13 +138,15 @@ Expand_packagelist ()
Discover_package_architectures () Discover_package_architectures ()
{ {
_LB_EXPANDED_PKG_LIST="${1}" local _LB_EXPANDED_PKG_LIST="${1}"
_LB_DISCOVERED_ARCHITECTURES="" local _LB_DISCOVERED_ARCHITECTURES=""
shift shift
if [ -e "${_LB_EXPANDED_PKG_LIST}" ] && [ -s "${_LB_EXPANDED_PKG_LIST}" ] if [ -e "${_LB_EXPANDED_PKG_LIST}" ] && [ -s "${_LB_EXPANDED_PKG_LIST}" ]
then then
local _LB_PACKAGE_LINE
local _LB_PACKAGE_LINE_PART
while read _LB_PACKAGE_LINE while read _LB_PACKAGE_LINE
do do
# Lines from the expanded package list may have multiple, space-separated packages # Lines from the expanded package list may have multiple, space-separated packages

View File

@ -9,11 +9,12 @@
## under certain conditions; see COPYING for details. ## under certain conditions; see COPYING for details.
# Note, updates _LB_PACKAGES
Check_package () Check_package ()
{ {
CHROOT="${1}" local CHROOT="${1}"
FILE="${2}" local FILE="${2}"
PACKAGE="${3}" local PACKAGE="${3}"
Check_installed "${CHROOT}" "${FILE}" "${PACKAGE}" Check_installed "${CHROOT}" "${FILE}" "${PACKAGE}"
@ -68,9 +69,9 @@ Remove_package ()
# 2 if package isn't installed and we aren't in an apt managed system # 2 if package isn't installed and we aren't in an apt managed system
Check_installed () Check_installed ()
{ {
CHROOT="${1}" local CHROOT="${1}"
FILE="${2}" local FILE="${2}"
PACKAGE="${3}" local PACKAGE="${3}"
if [ "${LB_BUILD_WITH_CHROOT}" = "true" ] && [ "${CHROOT}" = "chroot" ] if [ "${LB_BUILD_WITH_CHROOT}" = "true" ] && [ "${CHROOT}" = "chroot" ]
then then

View File

@ -44,11 +44,15 @@ Create_stagefile ()
Require_stagefile () Require_stagefile ()
{ {
local NAME
local FILES
local NUMBER
NAME="$(basename ${0})" NAME="$(basename ${0})"
FILES="${@}" FILES="${@}" #must be on separate line to 'local' declaration to avoid error
NUMBER="$(echo ${@} | wc -w)" NUMBER="$(echo ${@} | wc -w)"
CONTINUE=false local FILE
local CONTINUE=false
for FILE in ${FILES} for FILE in ${FILES}
do do
# Find at least one of the required stages # Find at least one of the required stages

View File

@ -11,7 +11,7 @@
Apt () Apt ()
{ {
CHROOT="${1}" local CHROOT="${1}"
shift shift
case "${LB_APT}" in case "${LB_APT}" in

View File

@ -50,10 +50,10 @@ Install_package
# Local functions # Local functions
Grub_live_entry () Grub_live_entry ()
{ {
LABEL="${1}" local LABEL="${1}"
KERNEL="${2}" local KERNEL="${2}"
INITRD="${3}" local INITRD="${3}"
APPEND="${4}" local APPEND="${4}"
LINUX_LIVE="${LINUX_LIVE}\ntitle\t\tDebian GNU/Linux - ${LABEL}" 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}" 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 () Grub_install_entry ()
{ {
LABEL="${1}" local LABEL="${1}"
KERNEL="${2}" local KERNEL="${2}"
INITRD="${3}" local INITRD="${3}"
APPEND="${4}" local APPEND="${4}"
APPEND="${APPEND} LB_BOOTAPPEND_INSTALL" local APPEND="${APPEND} LB_BOOTAPPEND_INSTALL"
if [ "${LABEL}" != "expert" ] && [ "${LABEL}" != "expertgui" ] if [ "${LABEL}" != "expert" ] && [ "${LABEL}" != "expertgui" ]; then
then
APPEND="${APPEND} --- quiet" APPEND="${APPEND} --- quiet"
fi fi

View File

@ -287,6 +287,8 @@ find /live/vmlinuz
EOM EOM
EOF 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')" 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:]]||')" hdddev="$(echo $rootpartition | sed -e 's|,[[:digit:]]||')"
echo "Root partition is $rootpartition, device is: $hdddev" echo "Root partition is $rootpartition, device is: $hdddev"

View File

@ -66,11 +66,11 @@ Grub_live_entry ()
Grub_install_entry () Grub_install_entry ()
{ {
LABEL="${1}" local LABEL="${1}"
TYPE="${2}" local TYPE="${2}"
KERNEL="${3}" local KERNEL="${3}"
INITRD="${4}" local INITRD="${4}"
APPEND="${5}" local APPEND="${5}"
# Drop "quiet" kernel parameter for expert entries # Drop "quiet" kernel parameter for expert entries
case $TYPE in case $TYPE in

View File

@ -137,6 +137,7 @@ USAGE="${PROGRAM} [--apt apt|aptitude]\n\
Local_arguments () Local_arguments ()
{ {
local LONG_OPTIONS
LONG_OPTIONS="apt:,apt-ftp-proxy:,apt-http-proxy:,apt-options:,aptitude-options:,debootstrap-options:,debootstrap-script:, 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:, apt-pipeline:,apt-recommends:,apt-secure:,apt-source-archives:,cache:,cache-indices:,cache-packages:,
cache-stages:,debconf-frontend:,debconf-priority:,dump, cache-stages:,debconf-frontend:,debconf-priority:,dump,
@ -165,6 +166,7 @@ Local_arguments ()
# Remove spaces added by indentation # Remove spaces added by indentation
LONG_OPTIONS="$(echo ${LONG_OPTIONS} | tr -d ' ')" LONG_OPTIONS="$(echo ${LONG_OPTIONS} | tr -d ' ')"
local ARGUMENTS
local ERR=0 local ERR=0
ARGUMENTS="$(getopt --longoptions ${LONG_OPTIONS} --name="${PROGRAM}" --options a:d:m:k:b:s:c:huv --shell sh -- "${@}")" || ERR=$? 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 case "${1}" in
--dump) --dump)
# Dump version # Dump version
local VERSION_DPKG
if [ $(which dpkg-query) ] if [ $(which dpkg-query) ]
then then
VERSION_DPKG="$(dpkg-query -f='${Version}' --show live-build)" VERSION_DPKG="$(dpkg-query -f='${Version}' --show live-build)"
@ -194,6 +197,7 @@ Local_arguments ()
Print_conffiles $(Common_config_files) Print_conffiles $(Common_config_files)
# Dump contents of directories that contain text files # Dump contents of directories that contain text files
local DIRECTORY
for DIRECTORY in config/package-lists config/apt config/preseed config/rootfs for DIRECTORY in config/package-lists config/apt config/preseed config/rootfs
do do
if Find_files "${DIRECTORY}" if Find_files "${DIRECTORY}"

View File

@ -151,8 +151,7 @@ case "${LB_ARCHITECTURES}" in
esac esac
Install_file() { Install_file() {
local FILE local FILE="${1}"
FILE="${1}"
Echo_debug "Installing file %s" "${FILE}" Echo_debug "Installing file %s" "${FILE}"
@ -166,9 +165,9 @@ Install_file() {
ARCHIVE_AREA="main" ARCHIVE_AREA="main"
fi fi
local TARGET local TARGET="${2}/${ARCHIVE_AREA}"
TARGET="${2}/${ARCHIVE_AREA}"
local SOURCE
SOURCE="$(dpkg -f ${FILE} Source | awk '{ print $1 }')" SOURCE="$(dpkg -f ${FILE} Source | awk '{ print $1 }')"
if [ -z "${SOURCE}" ] if [ -z "${SOURCE}" ]
@ -176,6 +175,7 @@ Install_file() {
SOURCE="$(basename ${FILE} | awk -F_ '{ print $1 }')" SOURCE="$(basename ${FILE} | awk -F_ '{ print $1 }')"
fi fi
local LETTER
case "${SOURCE}" in case "${SOURCE}" in
lib?*) lib?*)
LETTER="$(echo ${SOURCE} | sed 's|\(....\).*|\1|')" LETTER="$(echo ${SOURCE} | sed 's|\(....\).*|\1|')"
@ -198,14 +198,12 @@ Install_file() {
_LB_CACHE_DIR="$(pwd)/cache/installer_debian-installer" _LB_CACHE_DIR="$(pwd)/cache/installer_debian-installer"
Download_file () { Download_file () {
local _LB_TARGET local _LB_TARGET="${1}"
_LB_TARGET="${1}" local _LB_URL="${2}"
local _LB_URL
_LB_URL="${2}"
Echo_debug "Downloading file \`%s\` from \`%s\`" "${_LB_TARGET}" "${_LB_URL}" 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')" _LB_CACHE_FILE="${_LB_CACHE_DIR}/$(echo "${_LB_URL}" | sed 's|/|_|g')"
if [ ! -f "${_LB_CACHE_FILE}" ] if [ ! -f "${_LB_CACHE_FILE}" ]
@ -795,11 +793,9 @@ fi
Repack_initrd() Repack_initrd()
{ {
local TARGET_INITRD local TARGET_INITRD="${1}"
local INCLUDE_PATH local INCLUDE_PATH="${2}"
TARGET_INITRD="${1}" local REPACK_TMPDIR="unpacked-initrd"
INCLUDE_PATH="${2}"
REPACK_TMPDIR="unpacked-initrd"
Echo_debug "Repacking initrd \`%s\`" "${TARGET_INITRD}" Echo_debug "Repacking initrd \`%s\`" "${TARGET_INITRD}"
@ -816,6 +812,7 @@ Repack_initrd()
if [ ! -d "${INCLUDE_PATH}" ] if [ ! -d "${INCLUDE_PATH}" ]
then then
# Invoked the old way, just copy the preseeds # Invoked the old way, just copy the preseeds
local _FILE
for _FILE in ../config/preseed/*.cfg ../config/preseed/*.cfg.installer for _FILE in ../config/preseed/*.cfg ../config/preseed/*.cfg.installer
do do
if [ -e "${_FILE}" ] if [ -e "${_FILE}" ]
@ -825,7 +822,7 @@ Repack_initrd()
done done
else else
# New way, include target directory content in the initrd # New way, include target directory content in the initrd
REPACK_TMPDIR_ABS="${PWD}" local REPACK_TMPDIR_ABS="${PWD}"
cd "${INCLUDE_PATH}" cd "${INCLUDE_PATH}"
find -print0 | cpio -pumd0 --no-preserve-owner "${REPACK_TMPDIR_ABS}/" find -print0 | cpio -pumd0 --no-preserve-owner "${REPACK_TMPDIR_ABS}/"
cd "${OLDPWD}" cd "${OLDPWD}"