845 lines
22 KiB
Bash
Executable File
845 lines
22 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
## live-build(7) - System Build Scripts
|
|
## Copyright (C) 2016-2020 The Debian Live team
|
|
## 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="Install debian-installer into binary"
|
|
USAGE="${PROGRAM} [--force]"
|
|
|
|
# Processing arguments and configuration files
|
|
Init_config_data "${@}"
|
|
|
|
if [ "${_DEBUG}" = "true" ]
|
|
then
|
|
WGET_OPTIONS="${WGET_OPTIONS} --verbose"
|
|
elif [ "${_QUIET}" = "true" ]
|
|
then
|
|
WGET_OPTIONS="${WGET_OPTIONS} --quiet"
|
|
else
|
|
WGET_OPTIONS="${WGET_OPTIONS} --no-verbose"
|
|
fi
|
|
|
|
# Check d-i configuration
|
|
case "${LB_DEBIAN_INSTALLER}" in
|
|
cdrom|netinst|netboot|businesscard|live)
|
|
;;
|
|
|
|
none)
|
|
exit 0
|
|
;;
|
|
|
|
*)
|
|
Echo_error "debian-installer flavour %s not supported." "${LB_DEBIAN_INSTALLER}"
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
Echo_message "Begin installing debian-installer..."
|
|
|
|
# Requiring stage file
|
|
Require_stagefiles config bootstrap
|
|
|
|
# Checking stage file
|
|
Check_stagefile
|
|
|
|
# Acquire lock file
|
|
Acquire_lockfile
|
|
|
|
# Checking depends
|
|
Check_package host /usr/bin/wget wget
|
|
Check_package chroot /usr/bin/apt-ftparchive apt-utils
|
|
|
|
# Restoring cache
|
|
Restore_package_cache binary
|
|
|
|
# Installing depends
|
|
Install_package
|
|
|
|
# Setting destination directory
|
|
case "${LIVE_IMAGE_TYPE}" in
|
|
netboot)
|
|
DESTDIR="tftpboot/debian-install/${LB_ARCHITECTURES}"
|
|
;;
|
|
|
|
*)
|
|
DESTDIR="binary/install"
|
|
;;
|
|
esac
|
|
|
|
# Set d-i image type
|
|
case "${LB_DEBIAN_INSTALLER}" in
|
|
businesscard|netboot|netinst)
|
|
DI_IMAGE_TYPE="netboot"
|
|
;;
|
|
*)
|
|
case "${LIVE_IMAGE_TYPE}" in
|
|
netboot)
|
|
DI_IMAGE_TYPE="netboot"
|
|
;;
|
|
|
|
*)
|
|
DI_IMAGE_TYPE="cdrom"
|
|
;;
|
|
esac
|
|
;;
|
|
esac
|
|
|
|
# Set architecture-specific variables
|
|
case "${LB_ARCHITECTURES}" in
|
|
armel)
|
|
DEFAULT_FLAVOUR="$(echo ${LB_LINUX_FLAVOURS} | awk '{ print $1 }')"
|
|
case "${DI_IMAGE_TYPE}" in
|
|
cdrom)
|
|
DI_REMOTE_BASE="${DEFAULT_FLAVOUR}/cdrom"
|
|
;;
|
|
|
|
netboot)
|
|
DI_REMOTE_BASE="${DEFAULT_FLAVOUR}/netboot"
|
|
;;
|
|
esac
|
|
|
|
DI_REMOTE_KERNEL="vmlinuz"
|
|
DI_REMOTE_BASE_GTK="${DI_REMOTE_BASE}/gtk"
|
|
;;
|
|
|
|
powerpc)
|
|
case "${DI_IMAGE_TYPE}" in
|
|
cdrom)
|
|
DI_REMOTE_BASE="${LB_ARCHITECTURES}/cdrom"
|
|
;;
|
|
|
|
netboot)
|
|
DI_REMOTE_BASE="${LB_ARCHITECTURES}/netboot"
|
|
;;
|
|
esac
|
|
|
|
DI_REMOTE_KERNEL="vmlinux"
|
|
DI_REMOTE_BASE_GTK="${DI_REMOTE_BASE}/gtk"
|
|
;;
|
|
|
|
*)
|
|
case "${DI_IMAGE_TYPE}" in
|
|
netboot)
|
|
DI_REMOTE_BASE="netboot/debian-installer/${LB_ARCHITECTURES}"
|
|
DI_REMOTE_BASE_GTK="netboot/gtk/debian-installer/${LB_ARCHITECTURES}"
|
|
DI_REMOTE_KERNEL="linux"
|
|
;;
|
|
|
|
cdrom)
|
|
DI_REMOTE_BASE="cdrom"
|
|
DI_REMOTE_BASE_GTK="cdrom/gtk"
|
|
DI_REMOTE_KERNEL="vmlinuz"
|
|
;;
|
|
esac
|
|
;;
|
|
esac
|
|
|
|
Install_file() {
|
|
local FILE="${1}"
|
|
|
|
Echo_debug "Installing file %s" "${FILE}"
|
|
|
|
local ARCHIVE_AREA
|
|
ARCHIVE_AREA="$(dpkg -I ${FILE} | awk '/^.*Section: / { print $2 }')"
|
|
|
|
if echo "${ARCHIVE_AREA}" | grep -qs '/'
|
|
then
|
|
ARCHIVE_AREA="$(echo ${ARCHIVE_AREA} | awk -F/ '{ print $1 }')"
|
|
else
|
|
ARCHIVE_AREA="main"
|
|
fi
|
|
|
|
local TARGET="${2}/${ARCHIVE_AREA}"
|
|
|
|
local SOURCE
|
|
SOURCE="$(dpkg -f ${FILE} Source | awk '{ print $1 }')"
|
|
|
|
if [ -z "${SOURCE}" ]
|
|
then
|
|
SOURCE="$(basename ${FILE} | awk -F_ '{ print $1 }')"
|
|
fi
|
|
|
|
local LETTER
|
|
case "${SOURCE}" in
|
|
lib?*)
|
|
LETTER="$(echo ${SOURCE} | sed 's|\(....\).*|\1|')"
|
|
;;
|
|
|
|
*)
|
|
LETTER="$(echo ${SOURCE} | sed 's|\(.\).*|\1|')"
|
|
;;
|
|
esac
|
|
|
|
# Install directory
|
|
mkdir -p "${TARGET}"/"${LETTER}"/"${SOURCE}"
|
|
|
|
# Move files
|
|
cp "${FILE}" "${TARGET}"/"${LETTER}"/"${SOURCE}"
|
|
}
|
|
|
|
# Set absolute directory for caching; we require it when we call Download_file
|
|
# from a non-standard cwd.
|
|
_LB_CACHE_DIR="$(pwd)/cache/installer_debian-installer"
|
|
|
|
Download_file () {
|
|
local _LB_TARGET="${1}"
|
|
local _LB_URL="${2}"
|
|
|
|
Echo_debug "Downloading file \`%s\` from \`%s\`" "${_LB_TARGET}" "${_LB_URL}"
|
|
|
|
local _LB_CACHE_FILE
|
|
_LB_CACHE_FILE="${_LB_CACHE_DIR}/$(echo "${_LB_URL}" | sed 's|/|_|g')"
|
|
|
|
if [ ! -f "${_LB_CACHE_FILE}" ]
|
|
then
|
|
Echo_debug "Not cached, downloading fresh..."
|
|
mkdir -p ${_LB_CACHE_DIR}
|
|
if ! wget ${WGET_OPTIONS} -O "${_LB_CACHE_FILE}" "${_LB_URL}"
|
|
then
|
|
rm -f "${_LB_CACHE_FILE}"
|
|
|
|
Echo_error "Could not download file: %s" "${_LB_URL}"
|
|
exit 1
|
|
fi
|
|
else
|
|
Echo_debug "Using copy from cache..."
|
|
fi
|
|
|
|
# Use hardlink if same device
|
|
if [ "$(stat --printf %d "${_LB_CACHE_DIR}/")" = "$(stat --printf %d ./)" ]
|
|
then
|
|
CP_OPTIONS="-l"
|
|
fi
|
|
|
|
cp -f ${CP_OPTIONS} -- "${_LB_CACHE_FILE}" "${_LB_TARGET}"
|
|
}
|
|
|
|
VMLINUZ_DI="vmlinuz"
|
|
INITRD_DI="initrd.gz"
|
|
DESTDIR_DI="${DESTDIR}"
|
|
|
|
VMLINUZ_GI="gtk/vmlinuz"
|
|
INITRD_GI="gtk/initrd.gz"
|
|
DESTDIR_GI="${DESTDIR}/gtk"
|
|
|
|
# Debian Installer daily builds
|
|
DAILY_DI_URL="https://d-i.debian.org/daily-images/${LB_ARCHITECTURES}/daily"
|
|
|
|
case "${LB_DERIVATIVE}" in
|
|
false)
|
|
if [ "${LB_DEBIAN_INSTALLER_DISTRIBUTION}" = "daily" ]
|
|
then
|
|
# FIXME: variable name should be decupled from derivatves
|
|
LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION="sid"
|
|
|
|
URL="${DAILY_DI_URL}"
|
|
else
|
|
URL="${LB_MIRROR_DEBIAN_INSTALLER}/dists/${LB_DEBIAN_INSTALLER_DISTRIBUTION}/main/installer-${LB_ARCHITECTURES}/current/images"
|
|
fi
|
|
;;
|
|
|
|
true)
|
|
if [ "${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}" = "daily" ]
|
|
then
|
|
LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION="sid"
|
|
|
|
URL="${DAILY_DI_URL}"
|
|
else
|
|
URL="${LB_PARENT_MIRROR_DEBIAN_INSTALLER}/dists/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/main/installer-${LB_ARCHITECTURES}/current/images"
|
|
fi
|
|
esac
|
|
|
|
mkdir -p "${DESTDIR_DI}"
|
|
|
|
# Downloading debian-installer
|
|
Download_file "${DESTDIR}"/"${VMLINUZ_DI}" ${URL}/${DI_REMOTE_BASE}/${DI_REMOTE_KERNEL}
|
|
Download_file "${DESTDIR}"/"${INITRD_DI}" ${URL}/${DI_REMOTE_BASE}/initrd.gz
|
|
|
|
# Downloading graphical-installer
|
|
DOWNLOAD_GTK_INSTALLER=false
|
|
if [ "${LB_DEBIAN_INSTALLER_GUI}" = "true" ]
|
|
then
|
|
case "${LB_ARCHITECTURES}" in
|
|
amd64|i386)
|
|
DOWNLOAD_GTK_INSTALLER=true
|
|
;;
|
|
|
|
powerpc)
|
|
if [ "${LB_DEBIAN_INSTALLER}" = "netboot" ]
|
|
then
|
|
DOWNLOAD_GTK_INSTALLER=true
|
|
fi
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
if $DOWNLOAD_GTK_INSTALLER; then
|
|
mkdir -p "${DESTDIR_GI}"
|
|
Download_file "${DESTDIR}"/"${VMLINUZ_GI}" ${URL}/${DI_REMOTE_BASE_GTK}/${DI_REMOTE_KERNEL}
|
|
Download_file "${DESTDIR}"/"${INITRD_GI}" ${URL}/${DI_REMOTE_BASE_GTK}/initrd.gz
|
|
fi
|
|
|
|
# Only download additional packages if appropriate
|
|
if [ "${DI_IMAGE_TYPE}" != "netboot" ]
|
|
then
|
|
# Downloading additional packages
|
|
mkdir -p chroot/binary.deb/archives/partial
|
|
|
|
case "${LB_ARCHITECTURES}" in
|
|
amd64)
|
|
DI_REQ_PACKAGES="lilo grub-pc"
|
|
DI_PACKAGES="linux-image-amd64"
|
|
;;
|
|
|
|
i386)
|
|
DI_REQ_PACKAGES="lilo grub-pc"
|
|
DI_PACKAGES="linux-image-686-pae"
|
|
;;
|
|
|
|
powerpc)
|
|
DI_REQ_PACKAGES="yaboot"
|
|
DI_PACKAGES="linux-image-powerpc linux-image-powerpc64 linux-image-powerpc-smp"
|
|
;;
|
|
esac
|
|
|
|
DI_PACKAGES="${DI_PACKAGES} busybox cryptsetup mdadm lvm2 xfsprogs jfsutils"
|
|
|
|
case "${LB_MODE}" in
|
|
debian)
|
|
DI_REQ_PACKAGES="${DI_REQ_PACKAGES} console-setup keyboard-configuration kbd"
|
|
;;
|
|
esac
|
|
|
|
Echo_debug "DI_REQ_PACKAGES: %s" "${DI_REQ_PACKAGES}"
|
|
Echo_debug "DI_PACKAGES: %s" "${DI_PACKAGES}"
|
|
|
|
# Include firmware packages
|
|
if [ "${LB_FIRMWARE_BINARY}" = "true" ]
|
|
then
|
|
# Get all firmware packages names
|
|
mkdir -p cache/contents.binary
|
|
|
|
FIRMWARE_PACKAGES=""
|
|
|
|
# Manually add firmware-linux/non-free meta package
|
|
if [ "${LB_DERIVATIVE}" = "false" ] && echo ${LB_PARENT_ARCHIVE_AREAS} | grep -qs "non-free"
|
|
then
|
|
FIRMWARE_PACKAGES="${FIRMWARE_PACKAGES} firmware-linux"
|
|
fi
|
|
|
|
Firmware_List_From_Contents "${LB_PARENT_MIRROR_CHROOT}" "${LB_PARENT_DISTRIBUTION_CHROOT}" "${LB_PARENT_ARCHIVE_AREAS}"
|
|
|
|
if [ "${LB_DERIVATIVE}" = "true" ]
|
|
then
|
|
# Avoid downloading things twice if distributions are identical
|
|
DERIVATIVE_ARCHIVE_AREAS=""
|
|
if [ "${LB_DISTRIBUTION_CHROOT}" != "${LB_PARENT_DISTRIBUTION_CHROOT}" ]
|
|
then
|
|
DERIVATIVE_ARCHIVE_AREAS="${LB_ARCHIVE_AREAS}"
|
|
else
|
|
for _ARCHIVE_AREA in ${LB_ARCHIVE_AREAS}
|
|
do
|
|
if ! In_list ${_ARCHIVE_AREA} ${LB_PARENT_ARCHIVE_AREAS}
|
|
then
|
|
DERIVATIVE_ARCHIVE_AREAS="${DERIVATIVE_ARCHIVE_AREAS} ${DERIVATIVE_ARCHIVE_AREAS}"
|
|
fi
|
|
done
|
|
fi
|
|
|
|
if [ ! -z "${DERIVATIVE_ARCHIVE_AREAS}" ]
|
|
then
|
|
Firmware_List_From_Contents "${LB_MIRROR_CHROOT}" "${LB_DISTRIBUTION_CHROOT}" "${DERIVATIVE_ARCHIVE_AREAS}"
|
|
fi
|
|
fi
|
|
|
|
# Drop section and keep package names only
|
|
for _PACKAGE in ${FIRMWARE_PACKAGES}
|
|
do
|
|
DI_FIRMWARE_PACKAGES="${DI_FIRMWARE_PACKAGES} $(echo ${_PACKAGE} | awk -F/ '{ print $NF }')"
|
|
done
|
|
FIRMWARE_PACKAGES=""
|
|
fi
|
|
|
|
Echo_debug "DI_FIRMWARE_PACKAGES: %s" "${DI_FIRMWARE_PACKAGES}"
|
|
|
|
# Set apt command prefix
|
|
_LB_APT_COMMAND="apt-get ${APT_OPTIONS} -o Dir::Cache=/binary.deb -o Dir::State::status=/dev/null -o APT::Install-Recommends=false --download-only"
|
|
|
|
if [ "${LB_DEBIAN_INSTALLER}" = "live" ]
|
|
then
|
|
# We don't want to duplicate .debs of packages in binary/pool that are already
|
|
# installed to target/ via live-installer.
|
|
#
|
|
# However, we need to force various packages' inclusion in binary/pool as
|
|
# d-i does not support (for example) re-installing grub from target/ - the grub
|
|
# .debs must actually exist.
|
|
|
|
# Download .debs of the required packages
|
|
Chroot chroot ${_LB_APT_COMMAND} install ${DI_PACKAGES} ${DI_FIRMWARE_PACKAGES} ${DI_REQ_PACKAGES}
|
|
|
|
# Drop the packages already installed that d-i doesn't explicitly need
|
|
_REMAINING_PACKAGES="$(echo ${DI_FIRMWARE_PACKAGES} ${DI_REQ_PACKAGES} | sed -e 's# #|#g')"
|
|
_REMAINING_PACKAGES="$(Chroot_package_list chroot | grep -E -v "^(${_REMAINING_PACKAGES})\$")"
|
|
|
|
Echo_debug "'live' installer mode, dropping following unneeded debs: %s" "${_REMAINING_PACKAGES}"
|
|
for _PACKAGE in ${_REMAINING_PACKAGES}
|
|
do
|
|
rm -f chroot/binary.deb/archives/${_PACKAGE}_*.deb
|
|
done
|
|
else
|
|
# Download .debs of the required packages
|
|
Chroot chroot ${_LB_APT_COMMAND} install ${DI_PACKAGES} ${DI_FIRMWARE_PACKAGES} ${DI_REQ_PACKAGES}
|
|
fi
|
|
|
|
mv chroot/binary.deb ./
|
|
|
|
for _ARCHIVE_AREA in ${LB_PARENT_ARCHIVE_AREAS} ${LB_ARCHIVE_AREAS}; do
|
|
mkdir -p binary/pool/${_ARCHIVE_AREA}
|
|
done
|
|
|
|
Echo_debug "Installing binary debs"
|
|
if Find_files binary.deb/archives/*.deb
|
|
then
|
|
for FILE in binary.deb/archives/*.deb
|
|
do
|
|
Install_file "${FILE}" "binary/pool"
|
|
done
|
|
fi
|
|
|
|
if [ "${LB_DEBIAN_INSTALLER}" != "live" ]
|
|
then
|
|
# Including base debian packages
|
|
if ls cache/packages.bootstrap/*.deb > /dev/null 2>&1
|
|
then
|
|
Echo_debug "Installing bootstrap debs"
|
|
for FILE in cache/packages.bootstrap/*.deb
|
|
do
|
|
Install_file "${FILE}" "binary/pool"
|
|
done
|
|
else
|
|
Echo_error "Could not find packages in cache/packages.bootstrap."
|
|
Echo_error "You selected values of LB_CACHE, LB_CACHE_PACKAGES, LB_CACHE_STAGES and LB_DEBIAN_INSTALLER which will result in 'bootstrap' packages not being cached - these are required when integrating the Debian Installer."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
Echo_debug "Including local debs"
|
|
|
|
# Including local debs
|
|
if Find_files config/packages.binary/*_"${LB_ARCHITECTURES}".deb || Find_files config/packages/*_"${LB_ARCHITECTURES}".deb
|
|
then
|
|
for FILE in config/packages.binary/*_"${LB_ARCHITECTURES}".deb config/packages/*_"${LB_ARCHITECTURES}".deb
|
|
do
|
|
if [ -e "${FILE}" ]
|
|
then
|
|
Install_file "${FILE}" "binary/pool"
|
|
fi
|
|
done
|
|
fi
|
|
|
|
if Find_files config/packages.binary/*_all.deb || Find_files config/packages/*_all.deb
|
|
then
|
|
for FILE in config/packages.binary/*_all.deb config/packages/*_all.deb
|
|
do
|
|
if [ -e "${FILE}" ]
|
|
then
|
|
Install_file "${FILE}" "binary/pool"
|
|
fi
|
|
done
|
|
fi
|
|
|
|
# Generating deb indices
|
|
Echo_debug "Generating deb indices"
|
|
for _ARCHIVE_AREA in $(cd binary/pool && ls); do
|
|
INDICE_DIR="dists/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/${_ARCHIVE_AREA}/binary-${LB_ARCHITECTURES}"
|
|
mkdir -p "binary/${INDICE_DIR}"
|
|
|
|
mv binary chroot/root
|
|
cat > chroot/binary.sh << EOF
|
|
#!/bin/sh
|
|
cd /root/binary
|
|
apt-ftparchive packages "pool/${_ARCHIVE_AREA}" > "${INDICE_DIR}/Packages"
|
|
EOF
|
|
Chroot chroot "sh binary.sh"
|
|
rm -f chroot/binary.sh
|
|
mv chroot/root/binary ./
|
|
|
|
gzip -9 -c "binary/${INDICE_DIR}/Packages" > "binary/${INDICE_DIR}/Packages.gz"
|
|
|
|
# Fetching release
|
|
Download_file "binary/${INDICE_DIR}/Release" "${LB_PARENT_MIRROR_CHROOT}/${INDICE_DIR}/Release"
|
|
done
|
|
|
|
# Symlink firmware packages to /firmware
|
|
Echo_debug "Symlinking firmware packages"
|
|
if [ -n "${DI_FIRMWARE_PACKAGES}" ]
|
|
then
|
|
mkdir -p binary/firmware
|
|
cd binary/firmware
|
|
|
|
for _PACKAGE in ${DI_FIRMWARE_PACKAGES}
|
|
do
|
|
for _FILE in $(find ../pool -name "${_PACKAGE}_*.deb")
|
|
do
|
|
ln -sf ${_FILE} ./
|
|
done
|
|
done
|
|
|
|
cd "${OLDPWD}"
|
|
fi
|
|
|
|
# Udeb handling
|
|
mkdir -p binary.udeb/pool-udeb/main
|
|
cd binary.udeb
|
|
|
|
# Downloading udeb indices
|
|
Echo_debug "Downloading udeb indices"
|
|
Download_file Packages.gz "${LB_PARENT_MIRROR_CHROOT}"/dists/"${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}"/main/debian-installer/binary-"${LB_ARCHITECTURES}"/Packages.gz
|
|
gunzip -c Packages.gz > Packages
|
|
|
|
if [ "${LB_DERIVATIVE}" = "true" ]
|
|
then
|
|
Download_file Packages.derivative.gz "${LB_MIRROR_CHROOT}"/dists/"${LB_DEBIAN_INSTALLER_DISTRIBUTION}"/main/debian-installer/binary-"${LB_ARCHITECTURES}"/Packages.gz
|
|
gunzip -c Packages.derivative.gz > Packages.derivative
|
|
fi
|
|
|
|
Echo_debug "Extracting udeb package list"
|
|
|
|
UDEBS="$(awk '/Filename: / { print $2 }' Packages)"
|
|
UDEBS_DERIVED=""
|
|
|
|
if [ "${LB_DERIVATIVE}" = "true" ]
|
|
then
|
|
UDEBS_DERIVED="$(awk '/Filename: / { print $2 }' Packages.derivative)"
|
|
|
|
Echo_debug "Derivative mode, filtering replaced packages from parent list"
|
|
Echo_debug "Parent (orig): %s" "${UDEBS}"
|
|
Echo_debug "Derived: %s" "${UDEBS_DERIVED}"
|
|
# Filter parent packages to exclude those replaced by derivative
|
|
# We need to compare package names from lists of paths and filenames that include versions
|
|
_UDEBS_FILTERED=""
|
|
_UDEBS_DERIVED_NAMES=""
|
|
for _UDEB in ${UDEBS_DERIVED}
|
|
do
|
|
_UDEBS_DERIVED_NAMES="${_UDEBS_DERIVED_NAMES} $(basename ${_UDEB} | awk -F_ '{ print $1 }')"
|
|
done
|
|
for _UDEB in ${UDEBS}
|
|
do
|
|
if ! In_list "$(basename ${_UDEB} | awk -F_ '{ print $1 }')" ${_UDEBS_DERIVED_NAMES}
|
|
then
|
|
_UDEBS_FILTERED="${_UDEBS_FILTERED} ${_UDEB}"
|
|
fi
|
|
done
|
|
UDEBS="${_UDEBS_FILTERED}"
|
|
_UDEBS_FILTERED=""
|
|
_UDEBS_DERIVED_NAMES=""
|
|
Echo_debug "Parent (filtered): %s" "${UDEBS}"
|
|
fi
|
|
|
|
# Downloading udeb packages
|
|
Echo_message "Downloading udebs..."
|
|
|
|
UDEB_CACHE_DIR="../cache/packages.installer_debian-installer.udeb"
|
|
|
|
for UDEB in ${UDEBS}
|
|
do
|
|
_UDEB_FILENAME="$(basename ${UDEB})"
|
|
# Copy from cache if available, otherwise download
|
|
if [ -f "${UDEB_CACHE_DIR}/${_UDEB_FILENAME}" ]; then
|
|
Echo_debug "Copying %s from cache" "${UDEB}"
|
|
cp "${UDEB_CACHE_DIR}/${_UDEB_FILENAME}" ./
|
|
else
|
|
Echo_debug "Downloading %s" "${UDEB}"
|
|
wget ${WGET_OPTIONS} "${LB_PARENT_MIRROR_CHROOT}/${UDEB}"
|
|
fi
|
|
done
|
|
|
|
if [ "${LB_DERIVATIVE}" = "true" ]
|
|
then
|
|
Echo_debug "Moving on to derivative set"
|
|
for UDEB in ${UDEBS_DERIVED}
|
|
do
|
|
_UDEB_FILENAME="$(basename ${UDEB})"
|
|
# Copy from cache if available, otherwise download
|
|
if [ -f "${UDEB_CACHE_DIR}/${_UDEB_FILENAME}" ]; then
|
|
Echo_debug "Copying %s from cache" "${UDEB}"
|
|
cp "${UDEB_CACHE_DIR}/${_UDEB_FILENAME}" ./
|
|
else
|
|
Echo_debug "Downloading %s" "${UDEB}"
|
|
wget ${WGET_OPTIONS} "${LB_MIRROR_CHROOT}/${UDEB}"
|
|
fi
|
|
done
|
|
fi
|
|
|
|
# Caching udebs
|
|
Echo_debug "Refreshing udeb cache"
|
|
rm -rf "${UDEB_CACHE_DIR}"
|
|
mkdir -p "${UDEB_CACHE_DIR}"
|
|
cp *.udeb "${UDEB_CACHE_DIR}"
|
|
|
|
Echo_debug "Including local udebs"
|
|
|
|
# Including local udebs
|
|
if Find_files ../config/packages.binary/*_"${LB_ARCHITECTURES}".udeb || Find_files ../config/packages/*_"${LB_ARCHITECTURES}".udeb
|
|
then
|
|
for FILE in ../config/packages.binary/*_"${LB_ARCHITECTURES}".udeb ../config/packages/*_"${LB_ARCHITECTURES}".udeb
|
|
do
|
|
if [ -e "${FILE}" ]
|
|
then
|
|
Install_file "${FILE}" "pool-udeb"
|
|
|
|
# Prefer local udebs over downloaded udebs
|
|
rm -f "$(basename ${FILE} | awk -F_ '{ print $1 }')"_*.udeb
|
|
fi
|
|
done
|
|
fi
|
|
|
|
if Find_files ../config/packages.binary/*_all.udeb || Find_files ../config/packages/*_all.udeb
|
|
then
|
|
for FILE in ../config/packages.binary/*_all.udeb ../config/packages/*_all.udeb
|
|
do
|
|
if [ -e "${FILE}" ]
|
|
then
|
|
Install_file "${FILE}" "pool-udeb"
|
|
|
|
# Prefer local udebs over downloaded udebs
|
|
rm -f "$(basename ${FILE} | awk -F_ '{ print $1 }')"_*.udeb
|
|
fi
|
|
done
|
|
fi
|
|
|
|
Echo_debug "Generating exclude list"
|
|
|
|
# Excluding udebs
|
|
for LOCATION in "${LIVE_BUILD}/data/debian-cd" /usr/share/live/build/data/debian-cd
|
|
do
|
|
if [ -e "${LOCATION}" ]
|
|
then
|
|
grep -v "^#" "${LOCATION}/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/udeb_exclude" > exclude || true
|
|
grep -v "^#" "${LOCATION}/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/exclude-udebs" >> exclude || true
|
|
grep -v "^#" "${LOCATION}/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/exclude-udebs-${LB_ARCHITECTURES}" >> exclude || true
|
|
|
|
continue
|
|
fi
|
|
done
|
|
|
|
# Local exclude file
|
|
if [ -e ../config/debian-installer/udeb_exclude ]
|
|
then
|
|
cat ../config/debian-installer/udeb_exclude >> exclude
|
|
fi
|
|
|
|
# Excluding udebs from excludes because we want them to be in the image on purpose
|
|
sed -i -e 's|di-utils-exit-installer||' exclude # used for live-installer-launcher
|
|
if [ "${LB_DEBIAN_INSTALLER}" = "live" ]; then
|
|
sed -i -e 's|live-installer||' exclude
|
|
fi
|
|
|
|
# Remove all udebs to be excluded from inclusion
|
|
Echo_debug "Removing excluded udebs"
|
|
while read EXCLUDE; do
|
|
rm -f "${EXCLUDE}_*.udeb"
|
|
done < exclude
|
|
|
|
# Sort udebs into alphabetised pool structure
|
|
Echo_debug "Organising into pool structure"
|
|
for UDEB in ${UDEBS} ${UDEBS_DERIVED}; do
|
|
_UDEB_FILENAME="$(basename ${UDEB})"
|
|
if [ -f "${_UDEB_FILENAME}" ]; then
|
|
Install_file "${_UDEB_FILENAME}" "pool-udeb"
|
|
rm "${_UDEB_FILENAME}"
|
|
fi
|
|
done
|
|
|
|
# Creating udeb indices
|
|
Echo_debug "Generating udeb indices"
|
|
|
|
UDEB_INDICE_DIR="dists/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/main/debian-installer/binary-${LB_ARCHITECTURES}"
|
|
|
|
mkdir -p "${UDEB_INDICE_DIR}"
|
|
|
|
cd "${OLDPWD}"
|
|
|
|
mv binary.udeb chroot/root
|
|
cat > chroot/binary.sh << EOF
|
|
#!/bin/sh
|
|
cd /root/binary.udeb
|
|
apt-ftparchive packages "pool-udeb/main" > "${UDEB_INDICE_DIR}/Packages"
|
|
EOF
|
|
Chroot chroot "sh binary.sh"
|
|
rm -f chroot/binary.sh
|
|
mv chroot/root/binary.udeb ./
|
|
|
|
cd binary.udeb
|
|
gzip -9 -c "${UDEB_INDICE_DIR}/Packages" > "${UDEB_INDICE_DIR}/Packages.gz"
|
|
|
|
rm -f Packages* exclude
|
|
find . | cpio -dmpu "${OLDPWD}"/binary
|
|
cd "${OLDPWD}"
|
|
|
|
rm -rf binary.udeb
|
|
rm -rf binary.deb
|
|
|
|
# Generating release file
|
|
Echo_debug "Generating release file"
|
|
mv binary chroot/root
|
|
|
|
if [ -e chroot/etc/os-release ]
|
|
then
|
|
_VERSION="$(. chroot/etc/os-release && echo ${VERSION_ID})"
|
|
fi
|
|
|
|
if [ -n "${_VERSION}" ]; then
|
|
_LB_APT_VERSION_OPT='-o APT::FTPArchive::Release::Version="'"${_VERSION}"'"'
|
|
fi
|
|
|
|
case "${LB_PARENT_DISTRIBUTION_BINARY}" in
|
|
sid)
|
|
_SUITE="unstable"
|
|
;;
|
|
|
|
*)
|
|
_SUITE="${LB_PARENT_DISTRIBUTION_BINARY}"
|
|
;;
|
|
esac
|
|
|
|
cat > chroot/binary.sh << EOF
|
|
#!/bin/sh
|
|
cd /root/binary && apt-ftparchive \
|
|
-o APT::FTPArchive::Release::Origin="Debian" \
|
|
-o APT::FTPArchive::Release::Label="Debian" \
|
|
-o APT::FTPArchive::Release::Suite="${_SUITE}" \
|
|
${_LB_APT_VERSION_OPT} \
|
|
-o APT::FTPArchive::Release::Codename="${LB_PARENT_DISTRIBUTION_BINARY}" \
|
|
-o APT::FTPArchive::Release::Date="$(date -R)" \
|
|
-o APT::FTPArchive::Release::Architectures="${LB_ARCHITECTURES}" \
|
|
-o APT::FTPArchive::Release::Components="${LB_PARENT_ARCHIVE_AREAS}" \
|
|
-o APT::FTPArchive::Release::Description="Last updated: $(date -R)" \
|
|
release dists/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION} > dists/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}/Release
|
|
EOF
|
|
|
|
Chroot chroot "sh binary.sh"
|
|
rm -f chroot/binary.sh
|
|
mv chroot/root/binary ./
|
|
|
|
Echo_debug "Creating distribution directories/symlinks"
|
|
|
|
DISTRIBUTIONS="stable testing unstable"
|
|
|
|
if [ "${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION}" != "${LB_PARENT_DISTRIBUTION_BINARY}" ]
|
|
then
|
|
DISTRIBUTIONS="${DISTRIBUTIONS} ${LB_PARENT_DISTRIBUTION_BINARY}"
|
|
fi
|
|
|
|
case "${LIVE_IMAGE_TYPE}" in
|
|
hdd)
|
|
case "${LB_BINARY_FILESYSTEM}" in
|
|
fat*|ntfs)
|
|
# Creating dist directories
|
|
for DISTRIBUTION in ${DISTRIBUTIONS}
|
|
do
|
|
cp -a binary/dists/${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION} binary/dists/${DISTRIBUTION}
|
|
done
|
|
;;
|
|
esac
|
|
;;
|
|
|
|
*)
|
|
# Creating dist symlinks
|
|
for DISTRIBUTION in ${DISTRIBUTIONS}
|
|
do
|
|
ln -s ${LB_PARENT_DEBIAN_INSTALLER_DISTRIBUTION} binary/dists/${DISTRIBUTION}
|
|
done
|
|
|
|
ln -s . binary/debian
|
|
;;
|
|
esac
|
|
fi
|
|
|
|
Repack_initrd()
|
|
{
|
|
local TARGET_INITRD="${1}"
|
|
local INCLUDE_PATH="${2}"
|
|
local REPACK_TMPDIR="unpacked-initrd"
|
|
|
|
Echo_debug "Repacking initrd \`%s\`" "${TARGET_INITRD}"
|
|
|
|
if [ -d "${INCLUDE_PATH}" ]
|
|
then
|
|
INCLUDE_PATH=$(readlink -f ${INCLUDE_PATH})
|
|
fi
|
|
|
|
# cpio does not have a "extract to directory", so we must change directory
|
|
mkdir -p ${REPACK_TMPDIR}
|
|
cd ${REPACK_TMPDIR}
|
|
|
|
gzip -d < ../${TARGET_INITRD} | cpio -i --make-directories --no-absolute-filenames
|
|
if [ ! -d "${INCLUDE_PATH}" ]
|
|
then
|
|
# Invoked the old way, just copy the preseeds
|
|
local _FILE
|
|
for _FILE in ../config/preseed/*.cfg ../config/preseed/*.cfg.installer
|
|
do
|
|
if [ -e "${_FILE}" ]
|
|
then
|
|
cp "${_FILE}" .
|
|
fi
|
|
done
|
|
else
|
|
# New way, include target directory content in the initrd
|
|
local REPACK_TMPDIR_ABS="${PWD}"
|
|
cd "${INCLUDE_PATH}"
|
|
find -print0 | cpio -pumd0 --no-preserve-owner "${REPACK_TMPDIR_ABS}/"
|
|
cd "${OLDPWD}"
|
|
fi
|
|
find -print0 | cpio -H newc -o0 | gzip -9 > ../${TARGET_INITRD}
|
|
|
|
cd ..
|
|
rm -rf ${REPACK_TMPDIR}
|
|
}
|
|
|
|
Echo_debug "Repacking initrds where necessary"
|
|
|
|
# Preseed d-i by repacking the initrd in certain situations
|
|
if [ "${DI_IMAGE_TYPE}" = "netboot" ] && ( ls config/preseed/*.cfg > /dev/null 2>&1 || ls config/preseed/*.cfg.installer > /dev/null 2>&1 )
|
|
then
|
|
Repack_initrd "${DESTDIR}"/"${INITRD_DI}"
|
|
|
|
if [ -e "${DESTDIR}"/"${INITRD_GI}" ]
|
|
then
|
|
Repack_initrd "${DESTDIR}"/"${INITRD_GI}"
|
|
fi
|
|
fi
|
|
|
|
# Include content of config/includes.installer if exists and not empty
|
|
if [ -d config/includes.installer ] && [ -n "$(ls -A config/includes.installer)" ]
|
|
then
|
|
Repack_initrd "${DESTDIR}"/"${INITRD_DI}" config/includes.installer
|
|
|
|
if [ -e "${DESTDIR}"/"${INITRD_GI}" ]
|
|
then
|
|
Repack_initrd "${DESTDIR}"/"${INITRD_GI}" config/includes.installer
|
|
fi
|
|
fi
|
|
|
|
# Saving cache
|
|
Save_package_cache binary
|
|
|
|
# Removing depends
|
|
Remove_package
|
|
|
|
# Creating stage file
|
|
Create_stagefile
|