diff options
Diffstat (limited to 'functions')
-rwxr-xr-x | functions/aliases.sh | 2 | ||||
-rwxr-xr-x | functions/architectures.sh | 8 | ||||
-rwxr-xr-x | functions/arguments.sh | 1 | ||||
-rwxr-xr-x | functions/bootloaders.sh | 5 | ||||
-rwxr-xr-x | functions/breakpoints.sh | 2 | ||||
-rwxr-xr-x | functions/cache.sh | 5 | ||||
-rwxr-xr-x | functions/chroot.sh | 12 | ||||
-rwxr-xr-x | functions/chroot_bind_path.sh | 6 | ||||
-rwxr-xr-x | functions/conffile.sh | 4 | ||||
-rwxr-xr-x | functions/configuration.sh | 23 | ||||
-rwxr-xr-x | functions/defaults.sh | 2 | ||||
-rwxr-xr-x | functions/echo.sh | 13 | ||||
-rwxr-xr-x | functions/firmwarelists.sh | 1 | ||||
-rwxr-xr-x | functions/losetup.sh | 30 | ||||
-rwxr-xr-x | functions/packagelists.sh | 24 | ||||
-rwxr-xr-x | functions/packages.sh | 13 | ||||
-rwxr-xr-x | functions/stagefile.sh | 8 | ||||
-rwxr-xr-x | functions/wrapper.sh | 2 |
18 files changed, 108 insertions, 53 deletions
diff --git a/functions/aliases.sh b/functions/aliases.sh index c4fb634e2..bf77e4284 100755 --- a/functions/aliases.sh +++ b/functions/aliases.sh @@ -19,6 +19,7 @@ In_list () local NEEDLE="${1}" shift + local ITEM for ITEM in ${@} do if [ "${NEEDLE}" = "${ITEM}" ] @@ -32,6 +33,7 @@ In_list () Truncate () { + local FILE for FILE in ${@} do if [ ! -L ${FILE} ] diff --git a/functions/architectures.sh b/functions/architectures.sh index 01d2b1f74..3f9ccc527 100755 --- a/functions/architectures.sh +++ b/functions/architectures.sh @@ -11,9 +11,11 @@ Check_architectures () { - ARCHITECTURES="${@}" - VALID=false + local ARCHITECTURES + ARCHITECTURES="${@}" #must be on separate line to 'local' declaration to avoid error + local VALID=false + local ARCHITECTURE for ARCHITECTURE in ${ARCHITECTURES} do if [ "$(echo ${LB_ARCHITECTURES} | grep ${ARCHITECTURE})" ] @@ -50,6 +52,7 @@ Check_architectures () Check_crossarchitectures () { + local HOST if [ $(which dpkg) ] then HOST="$(dpkg --print-architecture)" @@ -57,6 +60,7 @@ Check_crossarchitectures () HOST="$(uname -m)" fi + local CROSS case "${HOST}" in amd64|i386|x86_64) CROSS="amd64 i386" diff --git a/functions/arguments.sh b/functions/arguments.sh index 5d406f4b5..f87593204 100755 --- a/functions/arguments.sh +++ b/functions/arguments.sh @@ -11,6 +11,7 @@ Arguments () { + local ARGUMENTS 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=$? diff --git a/functions/bootloaders.sh b/functions/bootloaders.sh index 36e132fb5..14e50ac4c 100755 --- a/functions/bootloaders.sh +++ b/functions/bootloaders.sh @@ -10,8 +10,9 @@ Is_Requested_Bootloader () { - OLDIFS="$IFS" - IFS="," + local OLDIFS="$IFS" + local IFS="," + local BOOTLOADER for BOOTLOADER in ${LB_BOOTLOADERS}; do if [ "${BOOTLOADER}" = "${1}" ]; then IFS="$OLDIFS" diff --git a/functions/breakpoints.sh b/functions/breakpoints.sh index 6896c0521..e1eff1966 100755 --- a/functions/breakpoints.sh +++ b/functions/breakpoints.sh @@ -11,7 +11,7 @@ Breakpoint () { - NAME="${1}" + local NAME="${1}" if [ "${_BREAKPOINTS}" = "true" ] then diff --git a/functions/cache.sh b/functions/cache.sh index 4e4c4b884..3e5c7ef70 100755 --- a/functions/cache.sh +++ b/functions/cache.sh @@ -11,7 +11,7 @@ Restore_package_cache () { - DIRECTORY="cache/packages.${1}" + local DIRECTORY="cache/packages.${1}" if [ "${LB_CACHE}" = "true" ] && [ "${LB_CACHE_PACKAGES}" = "true" ] then @@ -32,7 +32,7 @@ Restore_package_cache () Save_package_cache () { - DIRECTORY="cache/packages.${1}" + local DIRECTORY="cache/packages.${1}" if [ "${LB_CACHE}" = "true" ] && [ "${LB_CACHE_PACKAGES}" = "true" ] then @@ -47,6 +47,7 @@ Save_package_cache () mkdir -p "${DIRECTORY}" # Saving new cache + local PACKAGE for PACKAGE in chroot/var/cache/apt/archives/*.deb do if [ -e "${DIRECTORY}"/"$(basename ${PACKAGE})" ] 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' } diff --git a/functions/chroot_bind_path.sh b/functions/chroot_bind_path.sh index e6695dd2f..94a033e85 100755 --- a/functions/chroot_bind_path.sh +++ b/functions/chroot_bind_path.sh @@ -11,6 +11,9 @@ Chroot_bind_path () { + local CHROOT + local BIND_SRC + local BIND_DEST CHROOT="$(readlink -f ${1})" BIND_SRC="$(readlink -f ${2})" @@ -27,6 +30,9 @@ Chroot_bind_path () Chroot_unbind_path () { + local CHROOT + local BIND_SRC + local BIND_DEST CHROOT="$(readlink -f ${1})" BIND_SRC="$(readlink -f ${2})" diff --git a/functions/conffile.sh b/functions/conffile.sh index 15f16c93f..ceb11ea06 100755 --- a/functions/conffile.sh +++ b/functions/conffile.sh @@ -11,10 +11,12 @@ Get_conffiles () { + local FILES if [ -n "${LB_CONFIG}" ] then FILES="${LB_CONFIG}" else + local FILE for FILE in ${@} do FILES="${FILES} ${FILE} ${FILE}.${LB_ARCHITECTURES} ${FILE}.${DISTRIBUTION}" @@ -29,6 +31,7 @@ Get_conffiles () Read_conffiles () { + local CONFFILE for CONFFILE in $(Get_conffiles "${@}") do if [ -f "${CONFFILE}" ] @@ -46,6 +49,7 @@ Read_conffiles () Print_conffiles () { + local CONFFILE for CONFFILE in $(Get_conffiles "${@}") do if [ -f "${CONFFILE}" ] diff --git a/functions/configuration.sh b/functions/configuration.sh index 0fb84a962..70faa62a1 100755 --- a/functions/configuration.sh +++ b/functions/configuration.sh @@ -11,29 +11,30 @@ Get_configuration () { - _CONFIGURATION_FILE="${1}" - _FIELD_NAME="${2}" + local CONFIGURATION_FILE="${1}" + local FIELD_NAME="${2}" + local FIELD_BODY - if [ -e "${_CONFIGURATION_FILE}" ] + if [ -e "${CONFIGURATION_FILE}" ] 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 - echo ${_FIELD_BODY} + echo ${FIELD_BODY} } Set_configuration () { - _CONFIGURATION_FILE="${1}" - _FIELD_NAME="${2}" - _FIELD_BODY="${3}" + local CONFIGURATION_FILE="${1}" + local FIELD_NAME="${2}" + local FIELD_BODY="${3}" - if grep -qs "^${_FIELD_NAME}:" "${_CONFIGURATION_FILE}" + if grep -qs "^${FIELD_NAME}:" "${CONFIGURATION_FILE}" then # 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 # Append configuration - echo "${_FIELD_NAME}: ${_FIELD_BODY}" >> "${_CONFIGURATION_FILE}" + echo "${FIELD_NAME}: ${FIELD_BODY}" >> "${CONFIGURATION_FILE}" fi } diff --git a/functions/defaults.sh b/functions/defaults.sh index 786a9dc4c..14ec0efea 100755 --- a/functions/defaults.sh +++ b/functions/defaults.sh @@ -96,6 +96,7 @@ Set_config_defaults () # Setting mode (currently: debian, progress-linux) if [ $(which lsb_release) ] then + local _DISTRIBUTOR _DISTRIBUTOR="$(lsb_release -is | tr "[A-Z]" "[a-z]")" case "${_DISTRIBUTOR}" in @@ -624,6 +625,7 @@ Set_config_defaults () ;; esac + local _LB_BOOTAPPEND_PRESEED if [ -n "${LB_DEBIAN_INSTALLER_PRESEEDFILE}" ] then case "${LIVE_IMAGE_TYPE}" in diff --git a/functions/echo.sh b/functions/echo.sh index e019d8ed7..48cf3cf8e 100755 --- a/functions/echo.sh +++ b/functions/echo.sh @@ -12,7 +12,7 @@ exec 3>&1 Echo () { - STRING="${1}" + local STRING="${1}" shift printf "${STRING}\n" "${@}" >&3 @@ -21,7 +21,7 @@ Echo () Echo_debug () { if [ "${_DEBUG}" = "true" ]; then - STRING="${1}" + local STRING="${1}" shift printf "D: ${STRING}\n" "${@}" >&3 @@ -30,7 +30,7 @@ Echo_debug () Echo_error () { - STRING="${1}" + local STRING="${1}" shift local PREFIX="${RED}E${NO_COLOR}" @@ -45,7 +45,7 @@ Echo_message () { if [ "${_QUIET}" != "true" ] then - STRING="${1}" + local STRING="${1}" shift local PREFIX="${PURPLE}P${NO_COLOR}" @@ -60,7 +60,7 @@ Echo_message () Echo_verbose () { if [ "${_VERBOSE}" = "true" ]; then - STRING="${1}" + local STRING="${1}" shift printf "I: ${STRING}\n" "${@}" >&3 @@ -69,7 +69,7 @@ Echo_verbose () Echo_warning () { - STRING="${1}" + local STRING="${1}" shift local PREFIX="${YELLOW}W${NO_COLOR}" @@ -82,6 +82,7 @@ Echo_warning () Echo_file () { + local LINE while read -r LINE do echo "${1}: ${LINE}" >&3 diff --git a/functions/firmwarelists.sh b/functions/firmwarelists.sh index a31860622..345752de4 100755 --- a/functions/firmwarelists.sh +++ b/functions/firmwarelists.sh @@ -19,6 +19,7 @@ Firmware_List_From_Contents () { local DISTRO_CHROOT="${2}" local ARCHIVE_AREAS="${3}" + local _ARCHIVE_AREA for _ARCHIVE_AREA in ${ARCHIVE_AREAS} do local CONTENTS_URL="${MIRROR_CHROOT}/dists/${DISTRO_CHROOT}/${_ARCHIVE_AREA}/Contents-${LB_ARCHITECTURES}.gz" diff --git a/functions/losetup.sh b/functions/losetup.sh index c3dd59641..c91852f26 100755 --- a/functions/losetup.sh +++ b/functions/losetup.sh @@ -10,8 +10,8 @@ Lodetach () { - DEVICE="${1}" - ATTEMPT="${2:-1}" + local DEVICE="${1}" + local ATTEMPT="${2:-1}" if [ "${ATTEMPT}" -gt 3 ] then @@ -37,10 +37,12 @@ Lodetach () Losetup () { - DEVICE="${1}" - FILE="${2}" - PARTITION="${3:-1}" + local DEVICE="${1}" + local FILE="${2}" + local PARTITION="${3:-1}" + local FDISK_OUT + local LOOPDEVICE losetup --read-only --partscan "${DEVICE}" "${FILE}" FDISK_OUT="$(fdisk -l -u ${DEVICE} 2>&1)" Lodetach "${DEVICE}" @@ -53,6 +55,8 @@ Losetup () losetup --partscan "${DEVICE}" "${FILE}" else + local SECTORS + local OFFSET SECTORS="$(echo "$FDISK_OUT" | sed -ne "s|^$LOOPDEVICE[ *]*\([0-9]*\).*|\1|p")" OFFSET="$(expr ${SECTORS} '*' 512)" @@ -65,7 +69,7 @@ Losetup () # adapted from lib/ext2fs/mkjournal.c, default block size is 4096 bytes (/etc/mke2fs.conf). ext2fs_default_journal_size() { - SIZE="$1" + local SIZE="$1" if [ "${SIZE}" -lt "8" ]; then # 2048*4096 echo 0 elif [ "${SIZE}" -lt "128" ]; then # 32768*4096 @@ -83,9 +87,10 @@ ext2fs_default_journal_size() Calculate_partition_size_without_journal () { - WITHOUT_JOURNAL_ORIGINAL_SIZE="${1}" - WITHOUT_JOURNAL_FILESYSTEM="${2}" + local WITHOUT_JOURNAL_ORIGINAL_SIZE="${1}" + local WITHOUT_JOURNAL_FILESYSTEM="${2}" + local PERCENT case "${WITHOUT_JOURNAL_FILESYSTEM}" in ext2|ext3|ext4) PERCENT="6" @@ -100,11 +105,16 @@ Calculate_partition_size_without_journal () Calculate_partition_size () { - ORIGINAL_SIZE="${1}" - FILESYSTEM="${2}" + local ORIGINAL_SIZE="${1}" + local FILESYSTEM="${2}" case "${FILESYSTEM}" in 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}) PROJECTED_JOURNAL_SIZE=$(ext2fs_default_journal_size ${NON_JOURNAL_SIZE}) PROJECTED_PARTITION_SIZE=$(expr ${ORIGINAL_SIZE} + ${PROJECTED_JOURNAL_SIZE}) diff --git a/functions/packagelists.sh b/functions/packagelists.sh index 4701c3c70..ad31f4909 100755 --- a/functions/packagelists.sh +++ b/functions/packagelists.sh @@ -11,17 +11,20 @@ Expand_packagelist () { + local _LB_EXPAND_QUEUE _LB_EXPAND_QUEUE="$(basename "${1}")" shift while [ -n "${_LB_EXPAND_QUEUE}" ] do + local _LB_LIST_NAME + local _LB_EXPAND_QUEUE _LB_LIST_NAME="$(echo ${_LB_EXPAND_QUEUE} | cut -d" " -f1)" _LB_EXPAND_QUEUE="$(echo ${_LB_EXPAND_QUEUE} | cut -s -d" " -f2-)" - _LB_LIST_LOCATION="" - _LB_NESTED=0 - _LB_ENABLED=1 + local _LB_LIST_LOCATION="" + local _LB_NESTED=0 + local _LB_ENABLED=1 for _LB_SEARCH_PATH in ${@} do @@ -42,6 +45,7 @@ Expand_packagelist () do case "${_LB_LINE}" in \!*) + local _EXEC _EXEC="$(echo ${_LB_LINE} | sed -e 's|^!||')" case "${LB_BUILD_WITH_CHROOT}" in @@ -63,6 +67,10 @@ Expand_packagelist () fi _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_HAYSTACK="$(eval "echo \$LB_$(echo "${_LB_LINE}" | cut -d' ' -f2)")" @@ -87,6 +95,10 @@ Expand_packagelist () fi _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_HAYSTACK="$(eval "echo \$LB_$(echo "${_LB_LINE}" | cut -d' ' -f2)")" @@ -126,13 +138,15 @@ Expand_packagelist () Discover_package_architectures () { - _LB_EXPANDED_PKG_LIST="${1}" - _LB_DISCOVERED_ARCHITECTURES="" + local _LB_EXPANDED_PKG_LIST="${1}" + local _LB_DISCOVERED_ARCHITECTURES="" shift if [ -e "${_LB_EXPANDED_PKG_LIST}" ] && [ -s "${_LB_EXPANDED_PKG_LIST}" ] then + local _LB_PACKAGE_LINE + local _LB_PACKAGE_LINE_PART while read _LB_PACKAGE_LINE do # Lines from the expanded package list may have multiple, space-separated packages diff --git a/functions/packages.sh b/functions/packages.sh index f07bed35f..fa16b1161 100755 --- a/functions/packages.sh +++ b/functions/packages.sh @@ -9,11 +9,12 @@ ## under certain conditions; see COPYING for details. +# Note, updates _LB_PACKAGES Check_package () { - CHROOT="${1}" - FILE="${2}" - PACKAGE="${3}" + local CHROOT="${1}" + local FILE="${2}" + local PACKAGE="${3}" 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 Check_installed () { - CHROOT="${1}" - FILE="${2}" - PACKAGE="${3}" + local CHROOT="${1}" + local FILE="${2}" + local PACKAGE="${3}" if [ "${LB_BUILD_WITH_CHROOT}" = "true" ] && [ "${CHROOT}" = "chroot" ] then diff --git a/functions/stagefile.sh b/functions/stagefile.sh index 09168f5f4..9ef4789c9 100755 --- a/functions/stagefile.sh +++ b/functions/stagefile.sh @@ -44,11 +44,15 @@ Create_stagefile () Require_stagefile () { + local NAME + local FILES + local NUMBER NAME="$(basename ${0})" - FILES="${@}" + FILES="${@}" #must be on separate line to 'local' declaration to avoid error NUMBER="$(echo ${@} | wc -w)" - CONTINUE=false + local FILE + local CONTINUE=false for FILE in ${FILES} do # Find at least one of the required stages diff --git a/functions/wrapper.sh b/functions/wrapper.sh index 002de785e..e96e1ac4e 100755 --- a/functions/wrapper.sh +++ b/functions/wrapper.sh @@ -11,7 +11,7 @@ Apt () { - CHROOT="${1}" + local CHROOT="${1}" shift case "${LB_APT}" in |