summaryrefslogtreecommitdiffstats
path: root/system-build/scripts/build/bootstrap
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xsystem-build/scripts/build/bootstrap71
-rwxr-xr-xsystem-build/scripts/build/bootstrap_archive-keys77
-rwxr-xr-xsystem-build/scripts/build/bootstrap_archives273
-rwxr-xr-xsystem-build/scripts/build/bootstrap_cache86
-rwxr-xr-xsystem-build/scripts/build/bootstrap_debootstrap138
5 files changed, 645 insertions, 0 deletions
diff --git a/system-build/scripts/build/bootstrap b/system-build/scripts/build/bootstrap
new file mode 100755
index 0000000..48f2119
--- /dev/null
+++ b/system-build/scripts/build/bootstrap
@@ -0,0 +1,71 @@
+#!/bin/sh
+
+## live-build(7) - System Build Scripts
+## Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
+##
+## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
+## This is free software, and you are welcome to redistribute it
+## under certain conditions; see COPYING for details.
+
+
+set -e
+
+# Including common functions
+[ -e "${LIVE_BUILD}/scripts/build.sh" ] && . "${LIVE_BUILD}/scripts/build.sh" || . /usr/lib/live/build.sh
+
+# Automatically populating config tree
+if [ -x auto/config ] && [ ! -e .build/config ]
+then
+ Echo_message "Automatically populating config tree."
+ lb config
+fi
+
+# Setting static variables
+DESCRIPTION="$(Echo 'bootstrap a Debian system')"
+HELP=""
+USAGE="${PROGRAM} [--force]"
+
+Arguments "${@}"
+
+# Reading configuration files
+Read_conffiles config/all config/common config/bootstrap config/system config/binary config/source
+Set_defaults
+
+# Setup cleanup function
+Setup_cleanup
+
+# Bootstrapping system
+lb bootstrap_cache restore ${@}
+lb bootstrap_debootstrap ${@}
+lb bootstrap_archive-keys ${@}
+lb bootstrap_cache save ${@}
+
+# Configuring chroot
+lb chroot_devpts install ${@}
+lb chroot_proc install ${@}
+lb chroot_selinuxfs install ${@}
+lb chroot_sysfs install ${@}
+lb chroot_debianchroot install ${@}
+lb chroot_dpkg install ${@}
+lb chroot_tmpfs install ${@}
+lb chroot_sysv-rc install ${@}
+lb chroot_hosts install ${@}
+lb chroot_resolv install ${@}
+lb chroot_hostname install ${@}
+lb chroot_apt install ${@}
+
+lb bootstrap_archives binary ${@}
+
+# Deconfiguring chroot
+lb chroot_apt remove ${@}
+lb chroot_hostname remove ${@}
+lb chroot_resolv remove ${@}
+lb chroot_hosts remove ${@}
+lb chroot_sysv-rc remove ${@}
+lb chroot_tmpfs remove ${@}
+lb chroot_dpkg remove ${@}
+lb chroot_debianchroot remove ${@}
+lb chroot_sysfs remove ${@}
+lb chroot_selinuxfs remove ${@}
+lb chroot_proc remove ${@}
+lb chroot_devpts remove ${@}
diff --git a/system-build/scripts/build/bootstrap_archive-keys b/system-build/scripts/build/bootstrap_archive-keys
new file mode 100755
index 0000000..3f4fd45
--- /dev/null
+++ b/system-build/scripts/build/bootstrap_archive-keys
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+## live-build(7) - System Build Scripts
+## Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
+##
+## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
+## This is free software, and you are welcome to redistribute it
+## under certain conditions; see COPYING for details.
+
+
+set -e
+
+# Including common functions
+[ -e "${LIVE_BUILD}/scripts/build.sh" ] && . "${LIVE_BUILD}/scripts/build.sh" || . /usr/lib/live/build.sh
+
+# Setting static variables
+DESCRIPTION="$(Echo 'bootstrap non-Debian archive-signing-keys')"
+HELP=""
+USAGE="${PROGRAM} [--force]"
+
+Arguments "${@}"
+
+# Reading configuration files
+Read_conffiles config/all config/common config/bootstrap config/system config/binary config/source
+Set_defaults
+
+# TODO: allow verification against user-specified keyring
+# For now, we'll only validate against debian-keyring
+
+# TODO2: use chrooted validation rather than host system based one
+
+case "${LB_MODE}" in
+ progress-linux)
+ case "${LB_DISTRIBUTION}" in
+ artax*)
+ _KEYS="artax artax-backports"
+ ;;
+
+ baureo*)
+ _KEYS="baureo baureo-backports"
+ ;;
+
+ cairon*)
+ _KEYS="cairon cairon-backports"
+ ;;
+ esac
+
+ _URL="${LB_MIRROR_CHROOT}/project/pgp"
+ ;;
+esac
+
+for _KEY in ${_KEYS}
+do
+ Echo_message "Fetching archive-key ${_KEY}..."
+
+ wget -q "${_URL}/archive-key-${_KEY}.asc" -O chroot/key.asc
+ wget -q "${_URL}/archive-key-${_KEY}.asc.sig" -O chroot/key.asc.sig
+
+ if [ -e /usr/bin/gpgv ] && [ -e /usr/share/keyrings/debian-keyring.gpg ]
+ then
+ Echo_message "Verifying archive-key ${_KEY} against debian-keyring..."
+
+ /usr/bin/gpgv --quiet --keyring /usr/share/keyrings/debian-keyring.gpg chroot/key.asc.sig chroot/key.asc > /dev/null 2>&1 || { Echo_error "archive-key ${_KEY} has invalid signature."; return 1;}
+ else
+ Echo_warning "Skipping archive-key ${_KEY} verification, either gpgv or debian-keyring not available on host system..."
+ fi
+
+ Echo_message "Importing archive-key ${_KEY}..."
+
+ Chroot chroot "apt-key add key.asc"
+ rm -f chroot/key.asc chroot/key.asc.sig
+done
+
+Chroot chroot "apt-get update"
+
+# Creating stage file
+Create_stagefile .build/bootstrap_archive-keys
diff --git a/system-build/scripts/build/bootstrap_archives b/system-build/scripts/build/bootstrap_archives
new file mode 100755
index 0000000..4e07051
--- /dev/null
+++ b/system-build/scripts/build/bootstrap_archives
@@ -0,0 +1,273 @@
+#!/bin/sh
+
+## live-build(7) - System Build Scripts
+## Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
+##
+## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
+## This is free software, and you are welcome to redistribute it
+## under certain conditions; see COPYING for details.
+
+
+set -e
+
+# Including common functions
+[ -e "${LIVE_BUILD}/scripts/build.sh" ] && . "${LIVE_BUILD}/scripts/build.sh" || . /usr/lib/live/build.sh
+
+# Setting static variables
+DESCRIPTION="$(Echo 'manage /etc/apt/sources.list')"
+HELP=""
+USAGE="${PROGRAM} [--force]"
+
+_PASS="${1:-binary}"
+if [ -n "${1}" ]
+then
+ shift
+fi
+
+Arguments "${@}"
+
+# Reading configuration files
+Read_conffiles config/all config/common config/bootstrap config/system config/binary config/source
+Set_defaults
+
+# Requiring stage file
+Require_stagefile .build/config .build/bootstrap
+
+case "${LB_DERIVATIVE}" in
+ true)
+ _PARENT_FILE="sources.list.d/debian.list"
+ ;;
+
+ false)
+ _PARENT_FILE="sources.list"
+ ;;
+esac
+
+Echo_message "Configuring file /etc/apt/sources.list"
+
+# Checking stage file
+Check_stagefile .build/chroot_archives
+
+# Checking lock file
+Check_lockfile .lock
+
+# Creating lock file
+Create_lockfile .lock
+
+# Restoring cache
+Restore_cache cache/packages.chroot
+
+# Configure custom sources.list
+
+if echo "${LB_PARENT_MIRROR_CHROOT}" | grep -q '^file:/'
+then
+ Chroot_bind_path chroot "$(echo ${LB_PARENT_MIRROR_CHROOT} | sed -e 's|file:||')"
+fi
+
+cat > chroot/etc/apt/${_PARENT_FILE} << EOF
+deb ${LB_PARENT_MIRROR_CHROOT} ${LB_PARENT_DISTRIBUTION} ${LB_PARENT_ARCHIVE_AREAS}
+EOF
+
+if [ "${_PASS}" = "source" ] || [ "${LB_APT_SOURCE_ARCHIVES}" = "true" ]
+then
+ echo "deb-src ${LB_PARENT_MIRROR_CHROOT} ${LB_PARENT_DISTRIBUTION} ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/${_PARENT_FILE}
+fi
+
+if [ "${LB_DERIVATIVE}" = "true" ]
+then
+ rm -f chroot/etc/apt/sources.list.d/${LB_MODE}.list
+
+ _DISTRIBUTION="$(echo ${LB_DISTRIBUTION} | sed -e 's|-backports||')"
+
+ echo "deb ${LB_MIRROR_CHROOT} ${_DISTRIBUTION} ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
+
+ if [ "${_PASS}" = "source" ] || [ "${LB_APT_SOURCE_ARCHIVES}" = "true" ]
+ then
+ echo "deb-src ${LB_MIRROR_CHROOT} ${_DISTRIBUTION} ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
+ fi
+fi
+
+if [ "${LB_SECURITY}" = "true" ]
+then
+ case "${LB_MODE}" in
+ debian|progress-linux)
+ case "${LB_PARENT_DISTRIBUTION}" in
+ sid)
+
+ ;;
+
+ *)
+ echo "deb ${LB_PARENT_MIRROR_CHROOT_SECURITY} ${LB_PARENT_DISTRIBUTION}/updates ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/${_PARENT_FILE}
+
+ if [ "${_PASS}" = "source" ] || [ "${LB_APT_SOURCE_ARCHIVES}" = "true" ]
+ then
+ echo "deb-src ${LB_PARENT_MIRROR_CHROOT_SECURITY} ${LB_PARENT_DISTRIBUTION}/updates ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/${_PARENT_FILE}
+ fi
+ ;;
+ esac
+
+ if [ "${LB_MODE}" = progress-linux ]
+ then
+ echo "deb ${LB_MIRROR_CHROOT_SECURITY} ${_DISTRIBUTION}-security ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
+
+ if [ "${_PASS}" = "source" ] || [ "${LB_APT_SOURCE_ARCHIVES}" = "true" ]
+ then
+ echo "deb-src ${LB_MIRROR_CHROOT_SECURITY} ${_DISTRIBUTION}-security ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
+ fi
+ else
+ if [ "${LB_DERIVATIVE}" = "true" ]
+ then
+ echo "deb ${LB_MIRROR_CHROOT_SECURITY} ${_DISTRIBUTION}/updates ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
+
+ if [ "${_PASS}" = "source" ] || [ "${LB_APT_SOURCE_ARCHIVES}" = "true" ]
+ then
+ echo "deb-src ${LB_MIRROR_CHROOT_SECURITY} ${_DISTRIBUTION}/updates ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
+ fi
+ fi
+ fi
+ ;;
+ esac
+fi
+
+if [ "${LB_UPDATES}" = "true" ]
+then
+ echo "deb ${LB_PARENT_MIRROR_CHROOT} ${LB_PARENT_DISTRIBUTION}-updates ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/${_PARENT_FILE}
+
+ if [ "${_PASS}" = "source" ] || [ "${LB_APT_SOURCE_ARCHIVES}" = "true" ]
+ then
+ echo "deb-src ${LB_PARENT_MIRROR_CHROOT} ${LB_PARENT_DISTRIBUTION}-updates ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/${_PARENT_FILE}
+ fi
+
+ if [ "${LB_DERIVATIVE}" = "true" ]
+ then
+ echo "deb ${LB_MIRROR_CHROOT} ${_DISTRIBUTION}-updates ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
+
+ if [ "${_PASS}" = "source" ] || [ "${LB_APT_SOURCE_ARCHIVES}" = "true" ]
+ then
+ echo "deb-src ${LB_MIRROR_CHROOT} ${_DISTRIBUTION}-updates ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
+ fi
+ fi
+fi
+
+if [ "${LB_BACKPORTS}" = "true" ]
+then
+ case "${LB_MODE}" in
+ debian)
+ if [ "${LB_PARENT_DISTRIBUTION}" != "sid" ]
+ then
+ echo "deb ${LB_PARENT_MIRROR_CHROOT} ${LB_PARENT_DISTRIBUTION}-backports ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/${_PARENT_FILE}
+
+ if [ "${_PASS}" = "source" ] || [ "${LB_APT_SOURCE_ARCHIVES}" = "true" ]
+ then
+ echo "deb-src ${LB_PARENT_MIRROR_CHROOT} ${LB_PARENT_DISTRIBUTION}-backports ${LB_PARENT_ARCHIVE_AREAS}" >> chroot/etc/apt/${_PARENT_FILE}
+ fi
+ fi
+ ;;
+ esac
+
+ if [ "${LB_DERIVATIVE}" = "true" ]
+ then
+ echo "deb ${LB_MIRROR_CHROOT} ${_DISTRIBUTION}-backports ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
+
+ if [ "${_PASS}" = "source" ] || [ "${LB_APT_SOURCE_ARCHIVES}" = "true" ]
+ then
+ echo "deb-src ${LB_MIRROR_CHROOT} ${_DISTRIBUTION}-backports ${LB_ARCHIVE_AREAS}" >> chroot/etc/apt/sources.list.d/${LB_MODE}.list
+ fi
+ fi
+fi
+
+# Adding local apt sources (chroot)
+for FILE in config/archives/*.list config/archives/*.list.chroot
+do
+ if [ -e "${FILE}" ]
+ then
+ sed -e "s|@DISTRIBUTION@|${LB_DISTRIBUTION}|g" \
+ -e "s|@PARENT_DISTRIBUTION@|${LB_PARENT_DISTRIBUTION}|g" \
+ -e "s|@ARCHIVE_AREAS@|${LB_ARCHIVE_AREAS}|g" \
+ -e "s|@PARENT_ARCHIVE_AREAS@|${LB_PARENT_ARCHIVE_AREAS}|g" \
+ "${FILE}" > "chroot/etc/apt/sources.list.d/$(basename ${FILE} .chroot)"
+
+ if [ "${_PASS}" != "source" ] && [ "${LB_APT_SOURCE_ARCHIVES}" = "false" ]
+ then
+ # Strip out source archives
+ sed "/^deb-src /d" "chroot/etc/apt/sources.list.d/$(basename ${FILE} .chroot)"
+ fi
+ fi
+done
+
+# Adding local apt configuration (chroot)
+for FILE in config/archives/*.conf config/archives/*.conf.chroot
+do
+ if [ -e "${FILE}" ]
+ then
+ cp ${FILE} chroot/etc/apt/apt.conf.d/$(basename ${FILE} .chroot)
+ fi
+done
+
+# Adding local apt preferences (chroot)
+for FILE in config/archives/*.pref config/archives/*.pref.chroot
+do
+ if [ -e "${FILE}" ]
+ then
+ cp ${FILE} chroot/etc/apt/preferences.d/$(basename ${FILE} .chroot)
+ fi
+done
+
+# Check local archive keys
+if Find_files config/archives/*.key || \
+ Find_files config/archives/*.key.chroot
+then
+ for FILE in config/archives/*.key \
+ config/archives/*.key.chroot
+ do
+ if [ -e "${FILE}" ]
+ then
+ cp ${FILE} chroot/root
+ Chroot chroot "apt-key add /root/$(basename ${FILE})"
+ rm -f chroot/root/$(basename ${FILE})
+ fi
+ done
+fi
+
+# Check local keyring packages
+if Find_files config/archives/*.deb
+then
+ for PACKAGE in config/archives/*.deb
+ do
+ cp ${PACKAGE} chroot/root
+ Chroot chroot "dpkg -i /root/$(basename ${PACKAGE})"
+ rm -f chroot/root/$(basename ${PACKAGE})
+ done
+fi
+
+# Rebuild apt indices from scratch.
+# Due to the fact that apt doesn't understand
+# pinning on the fly, we need to manually remove
+# the cached indices and rebuild them again.
+rm -rf chroot/var/cache/apt/*.bin
+
+Apt chroot update
+
+# Installing keyring packages
+if [ -n "${LB_KEYRING_PACKAGES}" ]
+then
+ Apt chroot "install ${LB_KEYRING_PACKAGES}"
+fi
+
+rm -rf chroot/var/cache/apt/*.bin
+
+Apt chroot update
+
+if [ "${LB_DERIVATIVE}" = "true" ]
+then
+ Apt chroot install apt dpkg
+fi
+
+Apt chroot "upgrade"
+Apt chroot "dist-upgrade"
+
+# Saving cache
+Save_cache cache/packages.chroot
+
+# Creating stage file
+Create_stagefile .build/bootstrap_archives
diff --git a/system-build/scripts/build/bootstrap_cache b/system-build/scripts/build/bootstrap_cache
new file mode 100755
index 0000000..bef9e5e
--- /dev/null
+++ b/system-build/scripts/build/bootstrap_cache
@@ -0,0 +1,86 @@
+#!/bin/sh
+
+## live-build(7) - System Build Scripts
+## Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
+##
+## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
+## This is free software, and you are welcome to redistribute it
+## under certain conditions; see COPYING for details.
+
+
+set -e
+
+# Including common functions
+[ -e "${LIVE_BUILD}/scripts/build.sh" ] && . "${LIVE_BUILD}/scripts/build.sh" || . /usr/lib/live/build.sh
+
+# Setting static variables
+DESCRIPTION="$(Echo 'cache bootstrap stage')"
+HELP=""
+USAGE="${PROGRAM} [--force]"
+
+Arguments "${@}"
+
+# Reading configuration files
+Read_conffiles config/all config/common config/bootstrap config/system config/binary config/source
+Set_defaults
+
+# Check architecture
+Check_crossarchitectures
+
+for STAGE in ${LB_CACHE_STAGES}
+do
+ if [ "${STAGE}" = "bootstrap" ]
+ then
+ case "${1}" in
+ restore)
+ Echo_message "Restoring bootstrap stage from cache..."
+
+ # Checking stage file
+ Check_stagefile .build/bootstrap_cache.restore
+
+ if [ -d cache/bootstrap ]
+ then
+ # Checking lock file
+ Check_lockfile .lock
+
+ # Creating lock file
+ Create_lockfile .lock
+
+ # Removing old chroot
+ rm -rf chroot
+
+ # Restoring old cache
+ cp -a cache/bootstrap chroot
+
+ # Creating stage file
+ Create_stagefile .build/bootstrap_cache.restore
+ Create_stagefile .build/bootstrap
+
+ exit 0
+ fi
+ ;;
+
+ save)
+ Echo_message "Saving bootstrap stage to cache..."
+
+ # Checking stage file
+ Check_stagefile .build/bootstrap_cache.save
+
+ # Checking lock file
+ Check_lockfile .lock
+
+ # Creating lock file
+ Create_lockfile .lock
+
+ rm -rf cache/bootstrap
+
+ mkdir -p cache
+
+ cp -a chroot cache/bootstrap
+
+ # Creating stage file
+ Create_stagefile .build/bootstrap_cache.save
+ ;;
+ esac
+ fi
+done
diff --git a/system-build/scripts/build/bootstrap_debootstrap b/system-build/scripts/build/bootstrap_debootstrap
new file mode 100755
index 0000000..b95475e
--- /dev/null
+++ b/system-build/scripts/build/bootstrap_debootstrap
@@ -0,0 +1,138 @@
+#!/bin/sh
+
+## live-build(7) - System Build Scripts
+## Copyright (C) 2006-2015 Daniel Baumann <mail@daniel-baumann.ch>
+##
+## This program comes with ABSOLUTELY NO WARRANTY; for details see COPYING.
+## This is free software, and you are welcome to redistribute it
+## under certain conditions; see COPYING for details.
+
+
+set -e
+
+# Including common functions
+[ -e "${LIVE_BUILD}/scripts/build.sh" ] && . "${LIVE_BUILD}/scripts/build.sh" || . /usr/lib/live/build.sh
+
+# Setting static variables
+DESCRIPTION="$(Echo 'bootstrap a Debian system with debootstrap(8)')"
+HELP=""
+USAGE="${PROGRAM} [--force]"
+
+Arguments "${@}"
+
+# Reading configuration files
+Read_conffiles config/all config/common config/bootstrap config/system config/binary config/source
+Set_defaults
+
+if [ ! -x "$(which debootstrap 2>/dev/null)" ]
+then
+ echo "E: debootstrap - command not found"
+ echo "I: debootstrap can be obtained from http://ftp.debian.org/debian/pool/main/d/debootstrap/"
+ echo "I: On Debian based systems, debootstrap can be installed with 'apt-get install debootstrap'."
+ exit 1
+fi
+
+# Check architecture
+Check_crossarchitectures
+
+Echo_message "Begin bootstrapping system..."
+
+Check_package chroot bin/debootstrap debootstrap
+
+# Checking stage file
+Check_stagefile .build/bootstrap
+Check_stagefile .build/bootstrap_cache.restore
+
+# Checking lock file
+Check_lockfile .lock
+
+# Creating lock file
+Create_lockfile .lock
+
+# Creating chroot directory
+mkdir -p chroot
+
+# Setting debootstrap options
+if [ -n "${LB_ARCHITECTURES}" ]
+then
+ DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --arch=${LB_ARCHITECTURES}"
+fi
+
+if [ "${LB_ARCHIVE_AREAS}" != "main" ]
+then
+ # Modify archive areas to remove leading/trailing whitespaces and replace other whitepspace with commas
+ DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --components=$(echo ${LB_ARCHIVE_AREAS} | sed -e 's| |,|g')"
+fi
+
+if [ "${_VERBOSE}" = "true" ]
+then
+ DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --verbose"
+fi
+
+# If LB_APT_SECURE is false, do not check signatures of the Release file
+# (requires debootstrap >= 1.0.30)
+if [ "${LB_APT_SECURE}" = "false" ] && /usr/sbin/debootstrap --help | grep -qs '\-\-no-check-gpg'
+then
+ DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --no-check-gpg"
+fi
+
+# Include apt-transport-https
+if grep -qs '^deb https' config/archives/*.list ||
+ grep -qs '^deb https' config/archives/*.list.*
+then
+ DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --include=apt-transport-https,ca-certificates"
+fi
+
+if [ -x "/usr/sbin/debootstrap" ]
+then
+ if [ "${LB_CACHE_PACKAGES}" = "true" ]
+ then
+ if ls cache/packages.bootstrap/*.deb > /dev/null 2>&1
+ then
+ mkdir -p chroot/var/cache/apt/archives
+ cp cache/packages.bootstrap/*.deb chroot/var/cache/apt/archives
+ fi
+
+ Echo_breakage "Running debootstrap (download-only)... "
+ debootstrap ${DEBOOTSTRAP_OPTIONS} --download-only "${LB_PARENT_DISTRIBUTION}" chroot "${LB_PARENT_MIRROR_BOOTSTRAP}"
+
+ # Removing old cache
+ rm -f cache/packages.bootstrap/*.deb
+
+ # Saving new cache
+ mkdir -p cache/packages.bootstrap
+ cp chroot/var/cache/apt/archives/*.deb cache/packages.bootstrap
+ fi
+
+ Echo_breakage "Running debootstrap... "
+
+ # Run appropriate bootstrap, i.e. foreign or regular bootstrap
+ if [ "${LB_BOOTSTRAP_QEMU_ARCHITECTURES}" = "${LB_ARCHITECTURES}" ]; then
+
+ if [ -n "${LB_BOOTSTRAP_QEMU_EXCLUDE}" ]
+ then
+ DEBOOTSTRAP_OPTIONS="${DEBOOTSTRAP_OPTIONS} --exclude=$(echo ${LB_BOOTSTRAP_QEMU_EXCLUDE} | sed 's| *|,|g')"
+ fi
+
+ Echo_message "Bootstrap will be foreign"
+ debootstrap ${DEBOOTSTRAP_OPTIONS} --foreign "${LB_PARENT_DISTRIBUTION}" chroot "${LB_PARENT_MIRROR_BOOTSTRAP}"
+
+ Echo_message "Running debootstrap second stage under QEMU"
+ cp ${LB_BOOTSTRAP_QEMU_STATIC} chroot/usr/bin
+ Chroot chroot /bin/sh /debootstrap/debootstrap --second-stage
+ else
+ debootstrap ${DEBOOTSTRAP_OPTIONS} "${LB_PARENT_DISTRIBUTION}" chroot "${LB_PARENT_MIRROR_BOOTSTRAP}"
+ fi
+
+ # Deconfiguring debootstrap configurations
+ rm -f chroot/etc/hosts
+
+ # Removing bootstrap cache
+ rm -f chroot/var/cache/apt/archives/*.deb
+
+ # Creating stage file
+ Create_stagefile .build/bootstrap
+else
+ Echo_error "Can't process file /usr/bin/debootstrap (FIXME)"
+ exit 1
+fi