Generalizing internal Chroot(); by requiring its first argument to be the chroot directory.

This commit is contained in:
Daniel Baumann 2008-10-28 16:44:06 +01:00
parent 6696b019fe
commit 1c1e7db6c4
27 changed files with 71 additions and 70 deletions

View File

@ -37,7 +37,7 @@ Save_cache ()
if [ "${LH_CACHE}" = "enabled" ] && [ "${LH_CACHE_PACKAGES}" = "enabled" ]
then
# Cleaning current cache
Chroot "apt-get autoclean"
Chroot chroot "apt-get autoclean"
if ls chroot/var/cache/apt/archives/*.deb > /dev/null 2>&1
then

View File

@ -11,6 +11,7 @@ set -e
Chroot ()
{
CHROOT="${1}"; shift
COMMANDS="${@}"
# Executing commands in chroot
@ -18,10 +19,10 @@ Chroot ()
if [ "${LH_USE_FAKEROOT}" != "enabled" ]
then
${LH_ROOT_COMMAND} chroot chroot /usr/bin/env -i HOME="/root" PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" TERM="${TERM}" ftp_proxy="${LH_APT_FTP_PROXY}" http_proxy="${LH_APT_HTTP_PROXY}" DEBIAN_FRONTEND="${LH_DEBCONF_FRONTEND}" DEBIAN_PRIORITY="${LH_DEBCONF_PRIORITY}" DEBCONF_NOWARNINGS="${LH_DEBCONF_NOWARNINGS}" XORG_CONFIG="custom" ${COMMANDS}
${LH_ROOT_COMMAND} chroot "${CHROOT}" /usr/bin/env -i HOME="/root" PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin" TERM="${TERM}" ftp_proxy="${LH_APT_FTP_PROXY}" http_proxy="${LH_APT_HTTP_PROXY}" DEBIAN_FRONTEND="${LH_DEBCONF_FRONTEND}" DEBIAN_PRIORITY="${LH_DEBCONF_PRIORITY}" DEBCONF_NOWARNINGS="${LH_DEBCONF_NOWARNINGS}" XORG_CONFIG="custom" ${COMMANDS}
else
# Building with fakeroot/fakechroot
${LH_ROOT_COMMAND} chroot chroot ${COMMANDS}
${LH_ROOT_COMMAND} chroot "${CHROOT}" ${COMMANDS}
fi
return "${?}"

View File

@ -34,11 +34,11 @@ Install_package ()
then
case "${LH_APT}" in
apt|apt-get)
Chroot "apt-get install -o APT::Install-Recommends=false --yes ${_LH_PACKAGES}"
Chroot chroot "apt-get install -o APT::Install-Recommends=false --yes ${_LH_PACKAGES}"
;;
aptitude)
Chroot "aptitude install --without-recommends --assume-yes ${_LH_PACKAGES}"
Chroot chroot "aptitude install --without-recommends --assume-yes ${_LH_PACKAGES}"
;;
esac
fi
@ -50,11 +50,11 @@ Remove_package ()
then
case "${LH_APT}" in
apt|apt-get)
Chroot "apt-get remove --purge --yes ${_LH_PACKAGES}"
Chroot chroot "apt-get remove --purge --yes ${_LH_PACKAGES}"
;;
aptitude)
Chroot "aptitude purge --assume-yes ${_LH_PACKAGES}"
Chroot chroot "aptitude purge --assume-yes ${_LH_PACKAGES}"
;;
esac
fi
@ -72,7 +72,7 @@ Check_installed ()
case "${LH_CHROOT_BUILD}" in
enabled)
if Chroot "dpkg-query -s ${PACKAGE}" 2> /dev/null | grep -qs "Status: install"
if Chroot chroot "dpkg-query -s ${PACKAGE}" 2> /dev/null | grep -qs "Status: install"
then
INSTALL_STATUS=0
else
@ -82,7 +82,7 @@ Check_installed ()
disabled)
if which dpkg-query > /dev/null 2>&1
then
if Chroot "dpkg-query -s ${PACKAGE}" 2> /dev/null | grep -qs "Status: install"
if Chroot chroot "dpkg-query -s ${PACKAGE}" 2> /dev/null | grep -qs "Status: install"
then
INSTALL_STATUS=0
else

View File

@ -13,11 +13,11 @@ Apt ()
{
case "${LH_APT}" in
apt|apt-get)
Chroot apt-get ${APT_OPTIONS} ${@}
Chroot chroot apt-get ${APT_OPTIONS} ${@}
;;
aptitude)
Chroot aptitude ${APTITUDE_OPTIONS} ${@}
Chroot chroot aptitude ${APTITUDE_OPTIONS} ${@}
;;
esac
}

View File

@ -100,7 +100,7 @@ then
if [ -e chroot/chroot/"${EXCLUDE}" ]
then
# Run "rm" inside the chroot so it cannot possibly remove host files.
Chroot "rm -r chroot/${EXCLUDE}"
Chroot chroot "rm -r chroot/${EXCLUDE}"
else
Echo_warning "Excluded path does not exist: %s" "${EXCLUDE}"
fi

View File

@ -434,16 +434,16 @@ then
done
# Download .deb's that we just marked as "purged" which caused broken dependencies
Chroot ${_LH_APT_COMMAND} -f dist-upgrade
Chroot chroot ${_LH_APT_COMMAND} -f dist-upgrade
# Revert dpkg status file
mv chroot/var/lib/dpkg/status.tmp chroot/var/lib/dpkg/status
# Download .debs of the required packages
Chroot ${_LH_APT_COMMAND} install ${DI_REQ_PACKAGES}
Chroot chroot ${_LH_APT_COMMAND} install ${DI_REQ_PACKAGES}
else
# Download .debs of the required packages
Chroot ${_LH_APT_COMMAND} install ${DI_PACKAGES}
Chroot chroot ${_LH_APT_COMMAND} install ${DI_PACKAGES}
# Revert dpkg status file
mv chroot/var/lib/dpkg/status.tmp chroot/var/lib/dpkg/status

View File

@ -102,7 +102,7 @@ do
case "${LH_CHROOT_BUILD}" in
enabled)
if Chroot aespipe -e ${LH_ENCRYPTION} -T \
if Chroot chroot aespipe -e ${LH_ENCRYPTION} -T \
< chroot/filesystem.${LH_CHROOT_FILESYSTEM} \
> chroot/filesystem.${LH_CHROOT_FILESYSTEM}.tmp
then

View File

@ -142,7 +142,7 @@ case "${LH_CHROOT_BUILD}" in
mv binary.sh chroot
mv binary chroot
Chroot "sh binary.sh"
Chroot chroot "sh binary.sh"
# Move image
mv chroot/binary chroot/binary.iso ./

View File

@ -63,7 +63,7 @@ then
Expand_packagelist "${PACKAGESLIST}" "config/binary_local-packageslists" "config/chroot_local-packageslists" > chroot/root/"$(basename ${PACKAGESLIST})"
# Downloading additional packages
Chroot "xargs --arg-file=/root/$(basename ${PACKAGESLIST}) apt-get ${APT_OPTIONS} -o Dir::Cache=/binary.deb --download-only install"
Chroot chroot "xargs --arg-file=/root/$(basename ${PACKAGESLIST}) apt-get ${APT_OPTIONS} -o Dir::Cache=/binary.deb --download-only install"
# Remove package list
rm chroot/root/"$(basename ${PACKAGESLIST})"

View File

@ -45,7 +45,7 @@ Create_lockfile .lock
if [ "${LH_INITRAMFS}" = "casper" ]
then
# Add filesystem.manifest
Chroot "dpkg --get-selections" | awk '{ print $1 }' | sort -u > binary/casper/filesystem.manifest
Chroot chroot "dpkg --get-selections" | awk '{ print $1 }' | sort -u > binary/casper/filesystem.manifest
fi
# Add packages.list
@ -55,7 +55,7 @@ This file contains the list of all packages installed in this live system.
EOF
Chroot "dpkg -l" >> binary/packages.txt
Chroot chroot "dpkg -l" >> binary/packages.txt
cp binary/packages.txt binary.packages

View File

@ -147,7 +147,7 @@ case "${LH_CHROOT_FILESYSTEM}" in
case "${LH_CHROOT_BUILD}" in
enabled)
Chroot "genext2fs --size-in-blocks=${REAL_DIM} ${RESERVED_PERCENTAGE}=0 --root=chroot filesystem.${LH_CHROOT_FILESYSTEM}"
Chroot chroot "genext2fs --size-in-blocks=${REAL_DIM} ${RESERVED_PERCENTAGE}=0 --root=chroot filesystem.${LH_CHROOT_FILESYSTEM}"
# Move image
mv chroot/filesystem.${LH_CHROOT_FILESYSTEM} binary/${INITFS}
@ -189,7 +189,7 @@ case "${LH_CHROOT_FILESYSTEM}" in
case "${LH_CHROOT_BUILD}" in
enabled)
Chroot "mkfs.jffs2 ${JFFS2_OPTIONS} --root=chroot --output filesystem.jffs2"
Chroot chroot "mkfs.jffs2 ${JFFS2_OPTIONS} --root=chroot --output filesystem.jffs2"
# Move image
mv chroot/filesystem.jffs2 binary/${INITFS}
@ -263,7 +263,7 @@ case "${LH_CHROOT_FILESYSTEM}" in
case "${LH_CHROOT_BUILD}" in
enabled)
# Create image
Chroot "mksquashfs chroot filesystem.squashfs ${MKSQUASHFS_OPTIONS}"
Chroot chroot "mksquashfs chroot filesystem.squashfs ${MKSQUASHFS_OPTIONS}"
# Move image
${LH_ROOT_COMMAND} mv chroot/filesystem.squashfs binary/${INITFS}

View File

@ -148,10 +148,10 @@ esac
case "${LH_CHROOT_BUILD}" in
enabled)
Chroot "parted -s ${FREELO} mklabel ${PARTITION_TABLE_TYPE}" || true
Chroot "parted -s ${FREELO} mkpart primary ${PARTITION_TYPE} 0.0 100%" || true
Chroot "parted -s ${FREELO} set 1 boot on" || true
Chroot "parted -s ${FREELO} set 1 lba off" || true
Chroot chroot "parted -s ${FREELO} mklabel ${PARTITION_TABLE_TYPE}" || true
Chroot chroot "parted -s ${FREELO} mkpart primary ${PARTITION_TYPE} 0.0 100%" || true
Chroot chroot "parted -s ${FREELO} set 1 boot on" || true
Chroot chroot "parted -s ${FREELO} set 1 lba off" || true
if [ "${LH_BOOTLOADER}" = "syslinux" ]
then
@ -196,7 +196,7 @@ esac
case "${LH_CHROOT_BUILD}" in
enabled)
Chroot "mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}"
Chroot chroot "mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}"
;;
disabled)
@ -226,7 +226,7 @@ find /live/vmlinuz
EOM
EOF
rootpartition="$(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')"
usbdev="$(echo $rootpartition | sed -e 's|,[[:digit:]]||')"
echo "Root partition is $rootpartition, device is: $usbdev"
@ -239,7 +239,7 @@ EOF
#EOM
#EOF
#Chroot "sh grub.sh"
#Chroot chroot "sh grub.sh"
rm -f chroot/grub.sh
fi
@ -252,7 +252,7 @@ if [ "${LH_BOOTLOADER}" = "syslinux" ]
then
case "${LH_CHROOT_BUILD}" in
enabled)
Chroot "syslinux ${FREELO}"
Chroot chroot "syslinux ${FREELO}"
;;
disabled)

View File

@ -165,7 +165,7 @@ then
# Remove cdebootstrap-helper-diverts (needed at least for minimal flavours)
case "${LH_PACKAGES_LISTS}" in
stripped|minimal)
Chroot "dpkg -P cdebootstrap-helper-diverts"
Chroot chroot "dpkg -P cdebootstrap-helper-diverts"
;;
esac

View File

@ -57,7 +57,7 @@ do
fi
# Executing hook
Chroot "/root/${HOOK}"
Chroot chroot "/root/${HOOK}"
# Removing hook
rm -f chroot/root/"${HOOK}"
@ -69,5 +69,5 @@ done
if [ -n "${LH_HOOKS}" ] && [ "${LH_HOOKS}" != "none" ]
then
LH_DEBCONF_FRONTEND="readline" LH_DEBCONF_PRIORITY="low" LH_DEBCONF_NOWARNINGS="no" Chroot "${LH_HOOKS}"
LH_DEBCONF_FRONTEND="readline" LH_DEBCONF_PRIORITY="low" LH_DEBCONF_NOWARNINGS="no" Chroot chroot "${LH_HOOKS}"
fi

View File

@ -50,11 +50,11 @@ then
# Installing packages
case "${LH_APT}" in
apt|apt-get)
Chroot "xargs --arg-file=/root/chroot_packages apt-get ${APT_OPTIONS} install"
Chroot chroot "xargs --arg-file=/root/chroot_packages apt-get ${APT_OPTIONS} install"
;;
aptitude)
Chroot "xargs --arg-file=/root/chroot_packages aptitude ${APTITUDE_OPTIONS} install"
Chroot chroot "xargs --arg-file=/root/chroot_packages aptitude ${APTITUDE_OPTIONS} install"
;;
esac

View File

@ -50,15 +50,15 @@ Create_lockfile .lock
case "${LH_INTERACTIVE}" in
enabled|shell)
Echo_message "Pausing build: starting interactive shell..."
Chroot "/bin/bash --login"
Chroot chroot "/bin/bash --login"
;;
x11)
Echo_message "Pausing build: starting interactive X11..."
Chroot "startx"
Chroot chroot "startx"
;;
xnest)
Echo_message "Pausing build: starting interactive Xnest..."
#Chroot "" # FIXME
#Chroot chroot "" # FIXME
;;
esac

View File

@ -57,7 +57,7 @@ then
fi
# Executing hook
Chroot "/root/$(basename ${HOOK})"
Chroot chroot "/root/$(basename ${HOOK})"
# Removing hook
rm -f chroot/root/"$(basename ${HOOK})"

View File

@ -56,7 +56,7 @@ then
for PATCH in config/chroot_local-patches/*
do
Echo_message "Applying patch %s..." "${PATCH}"
Chroot "patch -p1" < ${PATCH}
Chroot chroot "patch -p1" < ${PATCH}
done
# Removing depends

View File

@ -55,7 +55,7 @@ then
# Copying local preseed
cp "${PRESEED}" chroot/root/preseed
Chroot "debconf-set-selections /root/preseed"
Chroot chroot "debconf-set-selections /root/preseed"
# Removing local preseed file
rm -f chroot/root/preseed

View File

@ -56,7 +56,7 @@ do
# Copying preseed
cp "${PRESEED}" chroot/root/preseed
Chroot "debconf-set-selections /root/preseed"
Chroot chroot "debconf-set-selections /root/preseed"
# Removing preseed file
rm -f chroot/root/preseed

View File

@ -108,7 +108,7 @@ case "${1}" in
# completed all the indices.
case "${LH_BOOTSTRAP_FLAVOUR}" in
stripped|minimal)
Chroot "apt-get update"
Chroot chroot "apt-get update"
;;
esac
@ -122,13 +122,13 @@ case "${1}" in
Install_package
# Generate Packages and Packages.gz
echo "cd /root/local-packages && apt-ftparchive packages . > Packages" | Chroot sh
echo "cd /root/local-packages && apt-ftparchive packages . > Packages" | Chroot chroot sh
gzip -9 -c chroot/root/local-packages/Packages > chroot/root/local-packages/Packages.gz
# Generate Release
echo "cd /root/local-packages && apt-ftparchive \
-o APT::FTPArchive::Release::Origin=chroot_local-packages \
release . > Release" | Chroot sh
release . > Release" | Chroot chroot
if [ "${LH_APT_SECURE}" = "enabled" ]
then
@ -161,7 +161,7 @@ case "${1}" in
Expire-Date: 0
%secring /root/local-package-keyring.sec
%pubring /root/local-package-keyring.pub
%commit" | Chroot "gpg --batch --gen-key" || _LH_RET=${?}
%commit" | Chroot chroot "gpg --batch --gen-key" || _LH_RET=${?}
case "${_LH_RET}" in
""|2)
@ -180,14 +180,14 @@ case "${1}" in
fi
# Sign release
Chroot "gpg --no-default-keyring --secret-keyring /root/local-package-keyring.sec \
Chroot chroot "gpg --no-default-keyring --secret-keyring /root/local-package-keyring.sec \
--keyring /root/local-package-keyring.pub -abs -o \
/root/local-packages/Release.gpg /root/local-packages/Release"
# Import key
Chroot "gpg --no-default-keyring --secret-keyring /root/local-package-keyring.sec \
Chroot chroot "gpg --no-default-keyring --secret-keyring /root/local-package-keyring.sec \
--keyring /root/local-package-keyring.pub --armor \
--export ${_LH_LOCAL_KEY_EMAIL}" | Chroot "apt-key add -"
--export ${_LH_LOCAL_KEY_EMAIL}" | Chroot chroot "apt-key add -"
# Remove temporary keyrings
rm chroot/root/local-package-keyring.pub
@ -258,7 +258,7 @@ case "${1}" in
if [ "${LH_APT}" = "aptitude" ] && [ ! -x /usr/bin/aptitude ]
then
Chroot "apt-get ${APT_OPTIONS} install aptitude"
Chroot chroot "apt-get ${APT_OPTIONS} install aptitude"
fi
else # Get fresh indices
# Check local gpg keys
@ -267,7 +267,7 @@ case "${1}" in
for FILE in config/chroot_sources/*.chroot.gpg
do
cp ${FILE} chroot/root
Chroot "apt-key add /root/$(basename ${FILE})"
Chroot chroot "apt-key add /root/$(basename ${FILE})"
rm -f chroot/root/$(basename ${FILE})
done
fi
@ -278,7 +278,7 @@ case "${1}" in
for PACKAGE in config/chroot_sources/*.deb
do
cp ${PACKAGE} chroot/root
Chroot "dpkg -i /root/$(basename ${PACKAGE})"
Chroot chroot "dpkg -i /root/$(basename ${PACKAGE})"
rm -f chroot/root/$(basename ${PACKAGE})
done
fi
@ -286,8 +286,8 @@ case "${1}" in
# Installing aptitude
if [ "${LH_APT}" = "aptitude" ] && [ ! -x /usr/bin/aptitude ]
then
Chroot "apt-get ${APT_OPTIONS} update"
Chroot "apt-get ${APT_OPTIONS} install aptitude"
Chroot chroot "apt-get ${APT_OPTIONS} update"
Chroot chroot "apt-get ${APT_OPTIONS} install aptitude"
fi
Apt update
@ -297,7 +297,7 @@ case "${1}" in
# Installing keyring packages
if [ -n "${LH_KEYRING_PACKAGES}" ]
then
Chroot "apt-get --yes --force-yes install ${LH_KEYRING_PACKAGES}"
Chroot chroot "apt-get --yes --force-yes install ${LH_KEYRING_PACKAGES}"
Apt update
fi
@ -395,7 +395,7 @@ case "${1}" in
for FILE in config/chroot_sources/*.binary.gpg
do
cp ${FILE} chroot/root
Chroot "apt-key add /root/$(basename ${FILE})"
Chroot chroot "apt-key add /root/$(basename ${FILE})"
rm -f chroot/root/$(basename ${FILE})
done
fi

View File

@ -54,7 +54,7 @@ Check_package chroot/usr/bin/symlinks symlinks
Install_package
# Converting symlinks
Chroot "symlinks -c -r -s /"
Chroot chroot "symlinks -c -r -s /"
# Removing depends
Remove_package

View File

@ -47,7 +47,7 @@ then
# Disable all
for FILE in chroot/etc/init.d/*
do
Chroot "update-rc.d -f $(basename ${FILE}) remove"
Chroot chroot "update-rc.d -f $(basename ${FILE}) remove"
done
# Re-enable all required (taken from -f standard chroot)
@ -56,7 +56,7 @@ then
if [ -f chroot/var/lib/dpkg/info/${PACKAGE}.postinst ]
then
# Re-configure if existing
Chroot "/var/lib/dpkg/info/${PACKAGE}.postinst configure"
Chroot chroot "/var/lib/dpkg/info/${PACKAGE}.postinst configure"
fi
done

View File

@ -64,13 +64,13 @@ then
# Installing tasks
case "${LH_TASKSEL}" in
aptitude)
Chroot "aptitude ${APTITUDE_OPTIONS} install ${LH_TASKS}"
Chroot chroot "aptitude ${APTITUDE_OPTIONS} install ${LH_TASKS}"
;;
tasksel)
for TASK in ${LH_TASKS}
do
Chroot "tasksel --debconf-apt-progress --logstderr install ${TASK}"
Chroot chroot "tasksel --debconf-apt-progress --logstderr install ${TASK}"
done
;;
esac

View File

@ -54,7 +54,7 @@ then
fi
# Download sources
Chroot "dpkg --get-selections" | awk '{ print $1 }' > source-selection.txt
Chroot chroot "dpkg --get-selections" | awk '{ print $1 }' > source-selection.txt
cat >> source-selection.txt << EOF
${LH_BOOTLOADER}
@ -107,7 +107,7 @@ MISSING=""
grep . source-selection.txt | \
while read PACKAGE
do
if ! Chroot "apt-get ${APT_OPTIONS} --download-only source ${PACKAGE}"
if ! Chroot chroot "apt-get ${APT_OPTIONS} --download-only source ${PACKAGE}"
then
MISSING="${MISSING} ${PACKAGE}"
fi
@ -123,7 +123,7 @@ EOF
for PACKAGE in ${MISSING}
do
Chroot "dpkg -l ${PACKAGE}" | tail -n1 >> source/missing-source.txt
Chroot chroot "dpkg -l ${PACKAGE}" | tail -n1 >> source/missing-source.txt
done
fi

View File

@ -101,7 +101,7 @@ cat >> chroot/source.sh << EOF
genisoimage ${GENISOIMAGE_OPTIONS} -o source.iso -r -J -l -cache-inodes source
EOF
Chroot "sh source.sh"
Chroot chroot "sh source.sh"
# Move image
mv chroot/source chroot/source.iso ./

View File

@ -95,9 +95,9 @@ esac
Echo_warning "!!! The following error/warning messages can be ignored !!!"
Losetup $FREELO source.img 0
Chroot "parted -s ${FREELO} mklabel msdos" || true
Chroot "parted -s ${FREELO} mkpart primary ${PARTITION_TYPE} 0.0 100%" || true
Chroot "parted -s ${FREELO} set 1 lba off" || true
Chroot chroot "parted -s ${FREELO} mklabel msdos" || true
Chroot chroot "parted -s ${FREELO} mkpart primary ${PARTITION_TYPE} 0.0 100%" || true
Chroot chroot "parted -s ${FREELO} set 1 lba off" || true
${LH_LOSETUP} -d ${FREELO}
Losetup $FREELO source.img 1
@ -119,7 +119,7 @@ case "${LH_BINARY_FILESYSTEM}" in
;;
esac
Chroot "mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}"
Chroot chroot "mkfs.${MKFS} ${MKFS_OPTIONS} ${FREELO}"
mkdir -p source.tmp
${LH_ROOT_COMMAND} mount ${FREELO} source.tmp