From 43c6a1c73ed18cea3c0dedcc2e81a5b7a3d85406 Mon Sep 17 00:00:00 2001 From: torben Date: Thu, 10 Dec 2015 16:55:37 +0100 Subject: More fakechroot features. --- builder/build-initramfs.sh | 76 +++++++++++++++++++++++++++++----------------- 1 file changed, 48 insertions(+), 28 deletions(-) (limited to 'builder/build-initramfs.sh') diff --git a/builder/build-initramfs.sh b/builder/build-initramfs.sh index f4e7f699..dc56def6 100755 --- a/builder/build-initramfs.sh +++ b/builder/build-initramfs.sh @@ -3,16 +3,14 @@ # region header -# Copyright Torben Sickert (t.sickert["~at~"]gmail.com) 29.10.2015 +# Copyright Torben Sickert (info["~at~"]torben.website) 29.10.2015 # Janosch Dobler (TODO) 29.10.2015 # License # ------- - # This library written by Torben Sickert and Janosch Dobler stand under a # creative commons naming 3.0 unported license. # see http://creativecommons.org/licenses/by/3.0/deed.de - # This tool provides a generic way to install systemd based remote linux # initramfs. @@ -52,10 +50,7 @@ # as file name) for lines containing a match to the given # PATTERN. By default, grep prints the matching lines. -# endregion - -# region ensure presence of needed dependencies - +## region ensure presence of needed dependencies set -o errexit build_initramfs__needed_location="$(dirname "${BASH_SOURCE[0]}")/dnbd3-rootfs" if ! [[ -d "$build_initramfs__needed_location" ]]; then @@ -76,20 +71,19 @@ if ! [[ -d "$build_initramfs__needed_location" ]]; then rm --recursive --force "$build_initramfs__temporary_repository_location" fi set +o errexit - -# endregion +## endregion source "$(dirname "${BASH_SOURCE[0]}")/dnbd3-rootfs/scripts/rebash/core.sh" core.import exceptions exceptions.activate core.import logging core.import utils +# endregion logging.set_commands_log_level debug logging.set_log_level critical # region properties - build_initramfs_dracut_parameter='--force --no-hostonly' build_initramfs_verbose='no' build_initramfs_debug='no' @@ -97,14 +91,11 @@ build_initramfs_target='' build_initramfs_create_system_image='' build_initramfs_cleanup='no' build_initramfs_dependencies=(bash cpio git test shift echo mktemp cat rm sed \ - gzip curl tar grep make gcc cmake readlink dirname dmsetup fakeroot) - + gzip curl tar grep make gcc cmake readlink dirname dmsetup fakeroot \ + fakechroot chroot qemu-nbd) # endregion - # region functions - ## region command line interface - function build_initramfs_print_usage_message() { # Prints a description about how to use this program. logging.cat << EOF @@ -221,7 +212,7 @@ function build_initramfs_parse_command_line() { } ## endregion - +## region helper function build_initramfs_initialize_dracut() { # Downloads and compiles dracut. # @@ -271,13 +262,10 @@ function build_initramfs_cleanup() { clean return $? } - +## endregion # endregion - # region controller - -# TODO handle fakeroot target feature. - +## region dependency checks utils.dependency_check "${build_initramfs_dependencies[*]}" # TODO check for existing kernel headers. # Find lib locations: $(gcc -print-prog-name=cc1plus) -v @@ -289,15 +277,48 @@ if ! ldconfig --print-cache | grep libz.so; then logging.critical "You have to install the compression library \"libz\". Otherwise we aren't able to compile dnbd3 for your kernel." exit 1 fi +## endregion if ! build_initramfs_parse_command_line "$@"; then build_initramfs_print_help_message "$0" exit 1 fi +## region handle delegated operations to specified target +if [[ "$build_initramfs_target" != '' ]]; then + build_initramfs__target="$build_initramfs_target" + if [[ -f "$build_initramfs_target" ]]; then + build_initramfs__target="$(mktemp --directory)" + # TODO + #qemu-nbd "$build_initramfs_target" "$build_initramfs__target" + fi + if [[ -d "$build_initramfs__target" ]]; then + build_initramfs__temporary_working_directory="${build_initramfs__target:0:-1}$(fakeroot \ + fakechroot chroot "$build_initramfs__target" mktemp --directory)" + mount --bind "$(pwd)" "$build_initramfs__temporary_working_directory" + build_initramfs__parameter_skip=false + build_initramfs__parameter_to_forward=() + for build_initramfs__parameter; do + if $build_initramfs__parameter_skip; then + build_initramfs__parameter_skip=false + elif [[ "$build_initramfs__parameter" == '-t' ]] || \ + [[ "$build_initramfs__parameter" == '--target' ]] + then + build_initramfs__parameter_skip=true + else + build_initramfs__parameter_to_forward+=("$build_initramfs__parameter") + fi + done + "${build_initramfs__temporary_working_directory}/${BASH_SOURCE[0]}" ${build_initramfs__parameter_to_forward[*]} + fi + exit 0 +fi +## endregion +## region handle dependencies which can be resolved automatically logging.info 'Checking dracut.' if ! [[ -d "$(dirname "${BASH_SOURCE[0]}")/dracut" ]]; then logging.info "Dracut isn't available yet loading it." build_initramfs_initialize_dracut fi + build_initramfs__dracut_modules_source='../../dnbd3-rootfs' build_initramfs__dracut_modules_target="$(dirname "${BASH_SOURCE[0]}")/dracut/modules.d/90dnbd3-rootfs" if [[ ! -L "$build_initramfs__dracut_modules_target" || "$(readlink \ @@ -313,6 +334,8 @@ then # ... "$(basename "$build_initramfs__dracut_modules_source")" \ # ... "$build_initramfs__dracut_modules_target" fi +## endregion +## region prepare and perform final dracut call build_initramfs__loglevel='' if [ "$build_initramfs_verbose" == 'yes' ]; then build_initramfs__loglevel='--verbose' @@ -334,18 +357,15 @@ else # NOTE: We deactivate our exception handle since dracut returns "1" if it # is launched with help parameter ("-h" or "--help"). exceptions.deactivate - dracut/dracut.sh --local $build_initramfs__loglevel --modules \ - "$build_initramfs__modules" ${build_initramfs_dracut_parameter[*]} \ - /boot/initramfs-test.img + "$(dirname "${BASH_SOURCE[0]}")/dracut/dracut.sh" --local \ + $build_initramfs__loglevel --modules "$build_initramfs__modules" \ + ${build_initramfs_dracut_parameter[*]} /boot/initramfs-test.img exceptions.activate fi exceptions.deactivate - +## endregion # endregion - # region vim modline - # vim: set tabstop=4 shiftwidth=4 expandtab: # vim: foldmethod=marker foldmarker=region,endregion: - # endregion -- cgit v1.2.3-55-g7522