From 7f1a4e4fc50c636d187472388924109e853ec69e Mon Sep 17 00:00:00 2001 From: Antonio Terceiro Date: Fri, 8 Aug 2008 22:20:56 -0300 Subject: Replacing file checking with ls by function calls Instead of repeatedly doing "ls ... > /dev/null 2>&1", just use a function that does exactly that. --- functions/aliases.sh | 5 +++++ helpers/lh_binary_chroot | 2 +- helpers/lh_binary_debian-installer | 12 ++++++------ helpers/lh_binary_includes | 12 ++++++------ helpers/lh_binary_local-hooks | 2 +- helpers/lh_binary_local-includes | 2 +- helpers/lh_binary_local-packageslists | 2 +- helpers/lh_chroot_local-hooks | 2 +- helpers/lh_chroot_local-includes | 2 +- helpers/lh_chroot_local-packages | 2 +- helpers/lh_chroot_local-packageslists | 2 +- helpers/lh_chroot_local-patches | 2 +- helpers/lh_chroot_local-preseed | 2 +- helpers/lh_chroot_sources | 34 +++++++++++++++++----------------- 14 files changed, 44 insertions(+), 39 deletions(-) diff --git a/functions/aliases.sh b/functions/aliases.sh index c4e0290..15ae2ae 100755 --- a/functions/aliases.sh +++ b/functions/aliases.sh @@ -17,6 +17,11 @@ Truncate () done } +Find_files () +{ + (ls "${@}" | grep -qs .) > /dev/null 2>&1 +} + In_list () { NEEDLES="${1}" diff --git a/helpers/lh_binary_chroot b/helpers/lh_binary_chroot index e78c725..9691bcc 100755 --- a/helpers/lh_binary_chroot +++ b/helpers/lh_binary_chroot @@ -77,7 +77,7 @@ then exit 0 fi -if [ "${LH_CACHE}" = "enabled" ] && ls cache/stages_rootfs/filesystem* > /dev/null 2>&1 +if [ "${LH_CACHE}" = "enabled" ] && Find_files cache/stages_rootfs/filesystem* then exit 0 fi diff --git a/helpers/lh_binary_debian-installer b/helpers/lh_binary_debian-installer index e579eec..5121596 100755 --- a/helpers/lh_binary_debian-installer +++ b/helpers/lh_binary_debian-installer @@ -400,7 +400,7 @@ then mv chroot/binary.deb ./ mv chroot/var/lib/dpkg/status.tmp chroot/var/lib/dpkg/status - if ls binary.deb/archives/*.deb > /dev/null 2>&1 + if Find_files binary.deb/archives/*.deb then for FILE in binary.deb/archives/*.deb do @@ -424,7 +424,7 @@ then fi # Including local debs - if ls ../config/binary_local-debs/*_"${LH_ARCHITECTURE}".deb > /dev/null 2>&1 + if Find_files ../config/binary_local-debs/*_"${LH_ARCHITECTURE}".deb then for FILE in ../config/binary_local-debs/*_"${LH_ARCHITECTURE}".deb do @@ -432,7 +432,7 @@ then done fi - if ls ../config/binary_local-debs/*_all.deb > /dev/null 2>&1 + if Find_files ../config/binary_local-debs/*_all.deb then for FILE in ../config/binary_local-debs/*_all.deb do @@ -480,7 +480,7 @@ then cp *.udeb ../cache/packages_debian-installer.udeb # Including local udebs - if ls ../config/binary_local-udebs/*_"${LH_ARCHITECTURE}".udeb > /dev/null 2>&1 + if Find_files ../config/binary_local-udebs/*_"${LH_ARCHITECTURE}".udeb then for FILE in ../config/binary_local-udebs/*_"${LH_ARCHITECTURE}".udeb do @@ -491,7 +491,7 @@ then done fi - if ls ../config/binary_local-udebs/*_all.udeb > /dev/null 2>&1 + if Find_files ../config/binary_local-udebs/*_all.udeb then for FILE in ../config/binary_local-udebs/*_all.udeb do @@ -580,7 +580,7 @@ then fi # Including preseeding files - if ls config/binary_debian_installer/preseed*.cfg > /dev/null 2>&1 + if Find_files config/binary_debian_installer/preseed*.cfg then cp config/binary_debian-installer/preseed*.cfg binary/install fi diff --git a/helpers/lh_binary_includes b/helpers/lh_binary_includes index f97d735..d2086b8 100755 --- a/helpers/lh_binary_includes +++ b/helpers/lh_binary_includes @@ -96,26 +96,26 @@ fi # Copying common templates if [ -d "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/common ] && \ -ls "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/common/* > /dev/null 2>&1 +Find_files "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/common/* then cp -r ${CP_OPTIONS} "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/common/* binary fi if [ -d "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/common."${ARCH}" ] && \ -ls "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/common."${ARCH}"/* > /dev/null 2>&1 +Find_files "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/common."${ARCH}"/* then cp -r ${CP_OPTIONS} "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/common."${ARCH}"/* binary fi # Copying live templates if [ -d "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/live ] && \ -ls "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/live/* > /dev/null 2>&1 +Find_files "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/live/* then cp -r ${CP_OPTIONS} "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/live/* binary fi if [ -d "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/live."${ARCH}" ] && \ -ls "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/live."${ARCH}"/* > /dev/null 2>&1 +Find_files "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/live."${ARCH}"/* then cp -r ${CP_OPTIONS} "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/live."${ARCH}"/* binary fi @@ -124,13 +124,13 @@ if [ "${LH_DEBIAN_INSTALLER}" != "disabled" ] then # Copying install templates if [ -d "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/install ] && \ - ls "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/install/* > /dev/null 2>&1 + Find_files "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/install/* then cp -r ${CP_OPTIONS} "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/install/* binary fi if [ -d "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/install."${ARCH}" ] && \ - ls "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/install."${ARCH}"/* > /dev/null 2>&1 + Find_files "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/install."${ARCH}"/* then cp -r ${CP_OPTIONS} "${LH_INCLUDES}"/"${LH_DISTRIBUTION}"/install."${ARCH}"/* binary fi diff --git a/helpers/lh_binary_local-hooks b/helpers/lh_binary_local-hooks index 455e86b..92c4ea0 100755 --- a/helpers/lh_binary_local-hooks +++ b/helpers/lh_binary_local-hooks @@ -43,7 +43,7 @@ Check_lockfile .lock Create_lockfile .lock # Processing local-hooks -if ls config/binary_local-hooks/* > /dev/null 2>&1 +if Find_files config/binary_local-hooks/* then for HOOK in config/binary_local-hooks/* do diff --git a/helpers/lh_binary_local-includes b/helpers/lh_binary_local-includes index 96bf0b6..bcc013b 100755 --- a/helpers/lh_binary_local-includes +++ b/helpers/lh_binary_local-includes @@ -42,7 +42,7 @@ Check_lockfile .lock # Creating lock file Create_lockfile .lock -if ls -A config/binary_local-includes/ | grep -qs . > /dev/null 2>&1 +if Find_files config/binary_local-includes/ then # Copying includes cd config/binary_local-includes diff --git a/helpers/lh_binary_local-packageslists b/helpers/lh_binary_local-packageslists index 2659416..144b1a6 100755 --- a/helpers/lh_binary_local-packageslists +++ b/helpers/lh_binary_local-packageslists @@ -42,7 +42,7 @@ Check_lockfile .lock # Creating lock file Create_lockfile .lock -if ls config/binary_local-packageslists/* > /dev/null 2>&1 +if Find_files config/binary_local-packageslists/* then # Restoring cache Restore_cache cache/packages_chroot diff --git a/helpers/lh_chroot_local-hooks b/helpers/lh_chroot_local-hooks index b0f9e50..0b8cd52 100755 --- a/helpers/lh_chroot_local-hooks +++ b/helpers/lh_chroot_local-hooks @@ -43,7 +43,7 @@ Check_lockfile .lock Create_lockfile .lock # Processing local-hooks -if ls config/chroot_local-hooks/* > /dev/null 2>&1 +if Find_files config/chroot_local-hooks/* then for HOOK in config/chroot_local-hooks/* do diff --git a/helpers/lh_chroot_local-includes b/helpers/lh_chroot_local-includes index afb5b84..c1308e1 100755 --- a/helpers/lh_chroot_local-includes +++ b/helpers/lh_chroot_local-includes @@ -42,7 +42,7 @@ Check_lockfile .lock # Creating lock file Create_lockfile .lock -if ls -A config/chroot_local-includes/ | grep -qs . > /dev/null 2>&1 +if Find_files config/chroot_local-includes/ then # Copying includes cd config/chroot_local-includes diff --git a/helpers/lh_chroot_local-packages b/helpers/lh_chroot_local-packages index 5b5800f..1ea7c73 100755 --- a/helpers/lh_chroot_local-packages +++ b/helpers/lh_chroot_local-packages @@ -42,7 +42,7 @@ Check_lockfile .lock # Creating lock file Create_lockfile .lock -if ls chroot/root/local-packages/*.deb > /dev/null 2>&1 +if Find_files chroot/root/local-packages/*.deb then gunzip < chroot/root/local-packages/Packages.gz | awk '/^Package: / { print $2 }' \ >> chroot/root/chroot_packages diff --git a/helpers/lh_chroot_local-packageslists b/helpers/lh_chroot_local-packageslists index f5fe3bb..ab88282 100755 --- a/helpers/lh_chroot_local-packageslists +++ b/helpers/lh_chroot_local-packageslists @@ -42,7 +42,7 @@ Check_lockfile .lock # Creating lock file Create_lockfile .lock -if ls config/chroot_local-packageslists/* > /dev/null 2>&1 +if Find_files config/chroot_local-packageslists/* then for PACKAGES_LIST in config/chroot_local-packageslists/* do diff --git a/helpers/lh_chroot_local-patches b/helpers/lh_chroot_local-patches index b40e114..ead253f 100755 --- a/helpers/lh_chroot_local-patches +++ b/helpers/lh_chroot_local-patches @@ -42,7 +42,7 @@ Check_lockfile .lock # Creating lock file Create_lockfile .lock -if ls -A config/chroot_local-patches/ | grep -qs . > /dev/null 2>&1 +if Find_files config/chroot_local-patches/ then # Restoring cache Restore_cache cache/packages_chroot diff --git a/helpers/lh_chroot_local-preseed b/helpers/lh_chroot_local-preseed index 057acdf..e279faa 100755 --- a/helpers/lh_chroot_local-preseed +++ b/helpers/lh_chroot_local-preseed @@ -42,7 +42,7 @@ Check_lockfile .lock # Creating lock file Create_lockfile .lock -if ls config/chroot_local-preseed/* > /dev/null 2>&1 +if Find_files config/chroot_local-preseed/* then # Check dependency Check_package chroot/usr/bin/debconf-set-selections debconf diff --git a/helpers/lh_chroot_sources b/helpers/lh_chroot_sources index 3d69cd6..4a4331e 100755 --- a/helpers/lh_chroot_sources +++ b/helpers/lh_chroot_sources @@ -68,7 +68,7 @@ case "${1}" in fi # Check local sources.list - if ls config/chroot_sources/*.chroot > /dev/null 2>&1 + if Find_files config/chroot_sources/*.chroot then echo "" >> chroot/etc/apt/sources.list echo "# Custom repositories" >> chroot/etc/apt/sources.list @@ -80,7 +80,7 @@ case "${1}" in fi # Configure local package repository - if ls config/chroot_local-packages/*.deb > /dev/null 2>&1 + if Find_files config/chroot_local-packages/*.deb then rm -rf chroot/root/local-packages mkdir -p chroot/root/local-packages @@ -91,17 +91,17 @@ case "${1}" in fi # Copy packages - if ls config/chroot_local-packages/*_"${LH_ARCHITECTURE}".deb > /dev/null 2>&1 + if Find_files config/chroot_local-packages/*_"${LH_ARCHITECTURE}".deb then cp ${CP_OPTIONS} config/chroot_local-packages/*_"${LH_ARCHITECTURE}".deb chroot/root/local-packages fi - if ls config/chroot_local-packages/*_all.deb > /dev/null 2>&1 + if Find_files config/chroot_local-packages/*_all.deb then cp ${CP_OPTIONS} config/chroot_local-packages/*_all.deb chroot/root/local-packages fi - if ls chroot/root/local-packages/*.deb > /dev/null 2>&1 + if Find_files chroot/root/local-packages/*.deb then # Restoring cache Restore_cache cache/packages_chroot @@ -138,7 +138,7 @@ case "${1}" in mv chroot/dev/random chroot/dev/random.orig cp -a chroot/dev/urandom chroot/dev/random - if ls cache/local-package-keyring.* >/dev/null 2>&1 + if Find_files cache/local-package-keyring.* then cp cache/local-package-keyring.* chroot/root else @@ -212,12 +212,12 @@ case "${1}" in # Update indices from cache if [ "${LH_CACHE_INDICES}" = "enabled" ] && [ -d cache/indices_bootstrap ] then - if ls cache/indices_bootstrap/secring.gpg* > /dev/null 2>&1 + if Find_files cache/indices_bootstrap/secring.gpg* then cp -f cache/indices_bootstrap/secring.gpg* chroot/etc/apt fi - if ls cache/indices_bootstrap/trusted.gpg* > /dev/null 2>&1 + if Find_files cache/indices_bootstrap/trusted.gpg* then cp -f cache/indices_bootstrap/trusted.gpg* chroot/etc/apt fi @@ -232,17 +232,17 @@ case "${1}" in cp -f cache/indices_bootstrap/srcpkgcache.bin chroot/var/cache/apt fi - if ls cache/indices_bootstrap/*_Packages > /dev/null 2>&1 + if Find_files cache/indices_bootstrap/*_Packages then cp -f cache/indices_bootstrap/*_Packages chroot/var/lib/apt/lists fi - if ls cache/indices_bootstrap/*_Sources > /dev/null 2>&1 + if Find_files cache/indices_bootstrap/*_Sources then cp -f cache/indices_bootstrap/*_Sources chroot/var/lib/apt/lists fi - if ls cache/indices_bootstrap/*_Release* > /dev/null 2>&1 + if Find_files cache/indices_bootstrap/*_Release* then cp -f cache/indices_bootstrap/*_Release* chroot/var/lib/apt/lists fi @@ -253,7 +253,7 @@ case "${1}" in fi else # Get fresh indices # Check local gpg keys - if ls config/chroot_sources/*.chroot.gpg > /dev/null 2>&1 + if Find_files config/chroot_sources/*.chroot.gpg then for FILE in config/chroot_sources/*.chroot.gpg do @@ -264,7 +264,7 @@ case "${1}" in fi # Check local keyring packages - if ls config/chroot_sources/*.deb > /dev/null 2>&1 + if Find_files config/chroot_sources/*.deb then for PACKAGE in config/chroot_sources/*.deb do @@ -301,14 +301,14 @@ case "${1}" in cp -f chroot/var/cache/apt/pkgcache.bin cache/indices_bootstrap - if ls chroot/var/cache/apt/srcpkgcache.bin > /dev/null 2>&1 + if Find_files chroot/var/cache/apt/srcpkgcache.bin then cp -f chroot/var/cache/apt/srcpkgcache.bin cache/indices_bootstrap fi cp -f chroot/var/lib/apt/lists/*_Packages cache/indices_bootstrap - if ls chroot/var/lib/apt/lists/*_Sources > /dev/null 2>&1 + if Find_files chroot/var/lib/apt/lists/*_Sources then cp -f chroot/var/lib/apt/lists/*_Sources cache/indices_bootstrap fi @@ -369,7 +369,7 @@ case "${1}" in fi # Check local sources.list - if ls config/chroot_sources/*.binary > /dev/null 2>&1 + if Find_files config/chroot_sources/*.binary then echo "" >> chroot/etc/apt/sources.list echo "# Custom repositories" >> chroot/etc/apt/sources.list @@ -381,7 +381,7 @@ case "${1}" in fi # Check local gpg keys - if ls config/chroot_sources/*.binary.gpg > /dev/null 2>&1 + if Find_files config/chroot_sources/*.binary.gpg then for FILE in config/chroot_sources/*.binary.gpg do -- cgit v1.0