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.
This commit is contained in:
Antonio Terceiro 2008-08-08 22:20:56 -03:00 committed by Daniel Baumann
parent 382d244050
commit 7f1a4e4fc5
14 changed files with 44 additions and 39 deletions

View File

@ -17,6 +17,11 @@ Truncate ()
done
}
Find_files ()
{
(ls "${@}" | grep -qs .) > /dev/null 2>&1
}
In_list ()
{
NEEDLES="${1}"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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