Compare commits
1 Commits
main
...
coderabbit
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9940d24096 |
@ -45,6 +45,7 @@ function create_new_rootfs_cache_tarball() {
|
|||||||
display_alert "rootfs cache created" "${cache_fname} [${cache_size}]" "info"
|
display_alert "rootfs cache created" "${cache_fname} [${cache_size}]" "info"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# create_new_rootfs_cache_via_debootstrap creates a root filesystem in SDCARD using mmdebstrap-based provisioning, configures locales and apt sources, installs aggregated packages (optionally desktop packages), performs chroot setup and cleanup (policy diverts, qemu handling, resolvconf, machine-id masking), and prepares the rootfs cache for packaging.
|
||||||
function create_new_rootfs_cache_via_debootstrap() {
|
function create_new_rootfs_cache_via_debootstrap() {
|
||||||
[[ ! -d "${SDCARD:?}" ]] && exit_with_error "create_new_rootfs_cache_via_debootstrap: ${SDCARD} is not a directory"
|
[[ ! -d "${SDCARD:?}" ]] && exit_with_error "create_new_rootfs_cache_via_debootstrap: ${SDCARD} is not a directory"
|
||||||
|
|
||||||
@ -57,41 +58,40 @@ function create_new_rootfs_cache_via_debootstrap() {
|
|||||||
|
|
||||||
# @TODO: one day: https://gitlab.mister-muffin.de/josch/mmdebstrap/src/branch/main/mmdebstrap
|
# @TODO: one day: https://gitlab.mister-muffin.de/josch/mmdebstrap/src/branch/main/mmdebstrap
|
||||||
|
|
||||||
# Obtain the latest debootstrap (which is just a shell script) from Debian or Ubuntu's git at the latest development version
|
# Obtain the latest debootstrap (which is just a shell script) from mister-muffin or Ubuntu's git
|
||||||
declare debootstrap_bin="" debootstrap_version="" debootstrap_wanted_dir="" debootstrap_default_script=""
|
declare debootstrap_bin="" debootstrap_version="" debootstrap_wanted_dir="" debootstrap_default_script=""
|
||||||
|
|
||||||
display_alert "Preparing debootstrap" "for ${DISTRIBUTION}'s ${RELEASE}" "info"
|
display_alert "Preparing debootstrap" "for ${DISTRIBUTION}'s ${RELEASE}" "info"
|
||||||
case "${DISTRIBUTION}" in
|
case "${DISTRIBUTION}" in
|
||||||
Ubuntu)
|
Ubuntu)
|
||||||
GIT_FIXED_WORKDIR="debootstrap-ubuntu-devel" fetch_from_repo "https://git.launchpad.net/ubuntu/+source/debootstrap" "debootstrap-ubuntu-devel" "tag:import/1.0.118ubuntu1.13"
|
export GIT_FIXED_WORKDIR="mmdebstrap-ubuntu-devel"
|
||||||
debootstrap_wanted_dir="${SRC}/cache/sources/debootstrap-ubuntu-devel"
|
#FIXME: branch should be a variable eventually
|
||||||
|
fetch_from_repo "https://git.launchpad.net/ubuntu/+source/mmdebstrap" "${GIT_FIXED_WORKDIR}" "branch:ubuntu/noble"
|
||||||
|
debootstrap_wanted_dir="${SRC}/cache/sources/${GIT_FIXED_WORKDIR}"
|
||||||
debootstrap_default_script="gutsy"
|
debootstrap_default_script="gutsy"
|
||||||
|
debootstrap_version="$(sed 's/.*(\(.*\)).*/\1/; q' "${debootstrap_wanted_dir}/debian/changelog")"
|
||||||
;;
|
;;
|
||||||
Debian)
|
Debian)
|
||||||
GIT_FIXED_WORKDIR="debootstrap-debian-devel" fetch_from_repo "https://salsa.debian.org/installer-team/debootstrap.git" "debootstrap-debian-devel" "branch:master"
|
export GIT_FIXED_WORKDIR="mmdebstrap-debian-devel"
|
||||||
debootstrap_wanted_dir="${SRC}/cache/sources/debootstrap-debian-devel"
|
#FIXME: branch should be a variable eventually
|
||||||
|
fetch_from_repo "https://gitlab.mister-muffin.de/josch/mmdebstrap" "${GIT_FIXED_WORKDIR}" "branch:main"
|
||||||
|
debootstrap_wanted_dir="${SRC}/cache/sources/${GIT_FIXED_WORKDIR}"
|
||||||
debootstrap_default_script="sid"
|
debootstrap_default_script="sid"
|
||||||
|
debootstrap_version="$(sed 's/^## \[\([^]]*\)\].*/\1/; q' "${debootstrap_wanted_dir}/CHANGELOG.md")"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
exit_with_error "Unknown distribution for debootstrap" "${DISTRIBUTION}"
|
exit_with_error "Unknown distribution for debootstrap" "${DISTRIBUTION}"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
debootstrap_bin="${debootstrap_wanted_dir}/debootstrap"
|
debootstrap_bin="${debootstrap_wanted_dir}/mmdebstrap"
|
||||||
debootstrap_version="$(sed 's/.*(\(.*\)).*/\1/; q' "${debootstrap_wanted_dir}/debian/changelog")"
|
|
||||||
run_host_command_logged chmod a+x "${debootstrap_bin}"
|
run_host_command_logged chmod a+x "${debootstrap_bin}"
|
||||||
display_alert "Debootstrap version" "'${debootstrap_version}' for ${debootstrap_bin}" "info"
|
display_alert "Debootstrap version" "'${debootstrap_version}' for ${debootstrap_bin}" "info"
|
||||||
|
|
||||||
# check if the debootstrap has the scripts/${RELEASE} script present, otherwise symlink it to debootstrap_default_script
|
display_alert "Installing base system with ${#AGGREGATED_PACKAGES_DEBOOTSTRAP[@]} packages" "Stage 1/1" "info"
|
||||||
if [[ ! -f "${debootstrap_wanted_dir}/scripts/${RELEASE}" ]]; then
|
|
||||||
display_alert "Symlinking" "debootstrap scripts/${RELEASE} to scripts/${debootstrap_default_script}" "info"
|
|
||||||
run_host_command_logged ln -sv "${debootstrap_wanted_dir}/scripts/${debootstrap_default_script}" "${debootstrap_wanted_dir}/scripts/${RELEASE}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
display_alert "Installing base system with ${#AGGREGATED_PACKAGES_DEBOOTSTRAP[@]} packages" "Stage 1/2" "info"
|
|
||||||
cd "${SDCARD}" || exit_with_error "cray-cray about SDCARD" "${SDCARD}" # this will prevent error sh: 0: getcwd() failed
|
cd "${SDCARD}" || exit_with_error "cray-cray about SDCARD" "${SDCARD}" # this will prevent error sh: 0: getcwd() failed
|
||||||
|
|
||||||
declare -a deboostrap_arguments=(
|
declare -a debootstrap_arguments=(
|
||||||
"--variant=minbase" # minimal base variant. go ask Debian about it.
|
"--variant=minbase" # minimal base variant. go ask Debian about it.
|
||||||
"--arch=${ARCH}" # the arch
|
"--arch=${ARCH}" # the arch
|
||||||
"'--include=${AGGREGATED_PACKAGES_DEBOOTSTRAP_COMMA}'" # from aggregation.py
|
"'--include=${AGGREGATED_PACKAGES_DEBOOTSTRAP_COMMA}'" # from aggregation.py
|
||||||
@ -99,38 +99,32 @@ function create_new_rootfs_cache_via_debootstrap() {
|
|||||||
)
|
)
|
||||||
|
|
||||||
# This is necessary to debootstrap from a non-official repo
|
# This is necessary to debootstrap from a non-official repo
|
||||||
[[ $ARCH == loong64 ]] && deboostrap_arguments+=("--keyring=/usr/share/keyrings/debian-ports-archive-keyring.gpg")
|
[[ $ARCH == loong64 ]] && debootstrap_arguments+=("--keyring=/usr/share/keyrings/debian-ports-archive-keyring.gpg")
|
||||||
# Small detour for local apt caching option.
|
# Small detour for local apt caching option.
|
||||||
local_apt_deb_cache_prepare "before debootstrap" # sets LOCAL_APT_CACHE_INFO
|
local_apt_deb_cache_prepare "before debootstrap" # sets LOCAL_APT_CACHE_INFO
|
||||||
if [[ "${LOCAL_APT_CACHE_INFO[USE]}" == "yes" ]]; then
|
if [[ "${LOCAL_APT_CACHE_INFO[USE]}" == "yes" ]]; then
|
||||||
deboostrap_arguments+=("--cache-dir=${LOCAL_APT_CACHE_INFO[HOST_DEBOOTSTRAP_CACHE_DIR]}") # cache .deb's used
|
debootstrap_arguments+=("--setup-hook='mkdir -p ${LOCAL_APT_CACHE_INFO[HOST_DEBOOTSTRAP_CACHE_DIR]} \"\$1\"/var/cache/apt/archives/'")
|
||||||
|
debootstrap_arguments+=("--setup-hook='sync-in ${LOCAL_APT_CACHE_INFO[HOST_DEBOOTSTRAP_CACHE_DIR]} /var/cache/apt/archives/'")
|
||||||
|
debootstrap_arguments+=("--customize-hook='sync-out /var/cache/apt/archives/ ${LOCAL_APT_CACHE_INFO[HOST_DEBOOTSTRAP_CACHE_DIR]}'")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
deboostrap_arguments+=("--foreign") # release name
|
debootstrap_arguments+=("${RELEASE}" "${SDCARD}/" "${debootstrap_apt_mirror}") # release, path and mirror; always last, positional arguments.
|
||||||
|
|
||||||
deboostrap_arguments+=("${RELEASE}" "${SDCARD}/" "${debootstrap_apt_mirror}") # release, path and mirror; always last, positional arguments.
|
run_host_command_logged "${debootstrap_bin}" "${debootstrap_arguments[@]}" || {
|
||||||
|
exit_with_error "mmdebstrap failed" "${debootstrap_bin} ${RELEASE} ${DESKTOP_APPGROUPS_SELECTED} ${DESKTOP_ENVIRONMENT} ${BUILD_MINIMAL}"
|
||||||
# Set DEBOOTSTRAP_DIR only for this invocation; if we instead export it, the second stage will fail
|
|
||||||
run_host_command_logged "DEBOOTSTRAP_DIR='${debootstrap_wanted_dir}'" "${debootstrap_bin}" "${deboostrap_arguments[@]}" || {
|
|
||||||
exit_with_error "Debootstrap first stage failed" "${debootstrap_bin} ${RELEASE} ${DESKTOP_APPGROUPS_SELECTED} ${DESKTOP_ENVIRONMENT} ${BUILD_MINIMAL}"
|
|
||||||
}
|
}
|
||||||
[[ ! -f ${SDCARD}/debootstrap/debootstrap ]] && exit_with_error "Debootstrap first stage did not produce marker file"
|
|
||||||
|
|
||||||
skip_target_check="yes" local_apt_deb_cache_prepare "after debootstrap first stage" # just for size reference in logs; skip the target check: debootstrap uses it for second stage.
|
skip_target_check="yes" local_apt_deb_cache_prepare "for mmdebstrap" # just for size reference in logs
|
||||||
|
|
||||||
deploy_qemu_binary_to_chroot "${SDCARD}" "rootfs" # undeployed near the end of this function
|
deploy_qemu_binary_to_chroot "${SDCARD}" "rootfs" # undeployed near the end of this function
|
||||||
|
|
||||||
display_alert "Installing base system" "Stage 2/2" "info"
|
[[ ! -f "${SDCARD}/bin/bash" ]] && exit_with_error "mmdebstrap did not produce /bin/bash"
|
||||||
declare -g -a if_error_find_files_sdcard=("debootstrap.log") # if command fails, go look for this file and show it's contents during error processing
|
|
||||||
declare -g if_error_detail_message="Debootstrap second stage failed ${RELEASE} ${DESKTOP_APPGROUPS_SELECTED} ${DESKTOP_ENVIRONMENT} ${BUILD_MINIMAL}"
|
|
||||||
chroot_sdcard LC_ALL=C LANG=C /debootstrap/debootstrap --second-stage
|
|
||||||
[[ ! -f "${SDCARD}/bin/bash" ]] && exit_with_error "Debootstrap first stage did not produce /bin/bash"
|
|
||||||
|
|
||||||
# Done with debootstrap. Clean-up it's litterbox.
|
# Done with mmdebstrap. Clean-up its litterbox.
|
||||||
display_alert "Cleaning up after debootstrap" "debootstrap cleanup" "info"
|
display_alert "Cleaning up after mmdebstrap" "mmdebstrap cleanup" "info"
|
||||||
run_host_command_logged rm -rf "${SDCARD}/var/cache/apt" "${SDCARD}/var/lib/apt/lists"
|
run_host_command_logged rm -rf "${SDCARD}/var/cache/apt" "${SDCARD}/var/lib/apt/lists"
|
||||||
|
|
||||||
local_apt_deb_cache_prepare "after debootstrap second stage" # just for size reference in logs
|
local_apt_deb_cache_prepare "after mmdebstrap cleanup" # just for size reference in logs
|
||||||
|
|
||||||
mount_chroot "${SDCARD}" # we mount the chroot here... it's un-mounted below when all is done, or by cleanup handler '' @TODO
|
mount_chroot "${SDCARD}" # we mount the chroot here... it's un-mounted below when all is done, or by cleanup handler '' @TODO
|
||||||
|
|
||||||
@ -271,7 +265,7 @@ function create_new_rootfs_cache_via_debootstrap() {
|
|||||||
undeploy_qemu_binary_from_chroot "${SDCARD}" "rootfs"
|
undeploy_qemu_binary_from_chroot "${SDCARD}" "rootfs"
|
||||||
|
|
||||||
# stage: make rootfs cache archive
|
# stage: make rootfs cache archive
|
||||||
display_alert "Ending debootstrap process and preparing cache" "$RELEASE" "info"
|
display_alert "Ending mmdebstrap process and preparing cache" "$RELEASE" "info"
|
||||||
wait_for_disk_sync "before tar rootfs"
|
wait_for_disk_sync "before tar rootfs"
|
||||||
|
|
||||||
# we're done with using the chroot which we mounted above.
|
# we're done with using the chroot which we mounted above.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user