diff options
| author | jandob | 2015-12-10 19:56:12 +0100 |
|---|---|---|
| committer | jandob | 2015-12-10 19:56:12 +0100 |
| commit | 71c239e718cdc5150fbf40eb79d5709407a16373 (patch) | |
| tree | ce0c1ab270195aac13ab326a3ba1e396cfc660f2 /builder | |
| parent | update rebash (diff) | |
| parent | more fakeroot support. (diff) | |
| download | systemd-init-71c239e718cdc5150fbf40eb79d5709407a16373.tar.gz systemd-init-71c239e718cdc5150fbf40eb79d5709407a16373.tar.xz systemd-init-71c239e718cdc5150fbf40eb79d5709407a16373.zip | |
Merge branch 'master' of git.openslx.org:openslx-ng/systemd-init
Diffstat (limited to 'builder')
| -rwxr-xr-x | builder/build-initramfs.sh | 97 | ||||
| -rwxr-xr-x | builder/dnbd3-rootfs/hooks/cmdline/prepare-kernel-command-line-parameter.sh | 3 | ||||
| -rwxr-xr-x | builder/dnbd3-rootfs/module-setup.sh | 25 |
3 files changed, 82 insertions, 43 deletions
diff --git a/builder/build-initramfs.sh b/builder/build-initramfs.sh index 45a54b2b..1d48f5ef 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,34 +71,31 @@ 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' +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) - + 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 @@ -133,6 +125,10 @@ function build_initramfs_print_command_line_option_description() { -i --create-system-image Creates an image under given path from current system. (default: "$build_initramfs_create_system_image"). +-t --target Creates an image against given target template filesystem. If not + explicitly speicifed current system will be used as template system + (default). + Additional dracut parameter and normal parameter can be deleimiter via a single dash (-) (default: "$build_initramfs_dracut_parameter"). EOF @@ -181,6 +177,15 @@ function build_initramfs_parse_command_line() { fi shift ;; + -t|--target) + shift + build_initramfs_target="$1" + if [[ "$build_initramfs_target" == '' ]]; then + logging.critical "This options needs a path create initramfs from." + return 1 + fi + shift + ;; -) shift while [[ "$1" =~ ^.+$ ]]; do @@ -207,7 +212,7 @@ function build_initramfs_parse_command_line() { } ## endregion - +## region helper function build_initramfs_initialize_dracut() { # Downloads and compiles dracut. # @@ -257,31 +262,63 @@ function build_initramfs_cleanup() { clean return $? } - +## endregion # endregion - # region controller - +## region dependency checks utils.dependency_check "${build_initramfs_dependencies[*]}" # TODO check for existing kernel headers. # Find lib locations: $(gcc -print-prog-name=cc1plus) -v -if false; then - logging.error "You have to install the compression library \"libz\". Otherwise we aren't able to compile dnbd3 for your kernel." - exit 1 -fi 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="$(fakeroot \ + fakechroot chroot "$build_initramfs__target" mktemp --directory)" + mount --bind "$(pwd)" \ + "${build_initramfs__target}${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 + fakeroot fakechroot chroot "${build_initramfs__target}" \ + "${build_initramfs__temporary_working_directory}/${BASH_SOURCE[0]}" \ + ${build_initramfs__parameter_to_forward[*]} + # TODO grap result from /boot/initramfs-test.img + 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 \ @@ -297,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' @@ -308,7 +347,6 @@ if [ "$build_initramfs_debug" == 'yes' ]; then fi if [[ "$build_initramfs_create_system_image" != '' ]]; then logging.info 'Create system image.' - echo "$build_initramfs_create_system_image" build_initramfs_create_qcow2_system "$build_initramfs_create_system_image" elif [[ "$build_initramfs_cleanup" == 'yes' ]]; then logging.info 'Removing distribution specific files.' @@ -318,18 +356,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 diff --git a/builder/dnbd3-rootfs/hooks/cmdline/prepare-kernel-command-line-parameter.sh b/builder/dnbd3-rootfs/hooks/cmdline/prepare-kernel-command-line-parameter.sh index 19865586..e81cf43d 100755 --- a/builder/dnbd3-rootfs/hooks/cmdline/prepare-kernel-command-line-parameter.sh +++ b/builder/dnbd3-rootfs/hooks/cmdline/prepare-kernel-command-line-parameter.sh @@ -19,7 +19,8 @@ local parameter for parameter in $(getargs BOOTIF=); do info "PXE given boot interface $parameter" local dracut_interface_name="bootnet:$(echo $parameter | \ - sed --regexp-extended 's/.{2}-((.{2}-){5}.{2})/\1/' | sed s/-/:/g)" + sed --regexp-extended 's/.{2}[:\-]((.{2}[:\-]){5}.{2})/\1/' | \ + sed s/-/:/g)" info "Dracut interface name is: $dracut_interface_name" echo -n " ifname=$dracut_interface_name" >> \ "${writeable_proc_cmdline_path}cmdline" diff --git a/builder/dnbd3-rootfs/module-setup.sh b/builder/dnbd3-rootfs/module-setup.sh index 9101851c..ead0c99c 100755 --- a/builder/dnbd3-rootfs/module-setup.sh +++ b/builder/dnbd3-rootfs/module-setup.sh @@ -16,13 +16,13 @@ clean() { # dracut itself. if [[ -f "$moddir/binaries/nbd/nbd.ko" ]]; then - utils_clean_nbd "$moddir/binaries/nbd/" + build_clean_nbd "$moddir/binaries/nbd/" fi if [[ -f "$moddir/binaries/dnbd3/build/dnbd3.ko" || ! -f "$moddir/binaries/dnbd3/build/dnbd3-client" ]]; then - utils_clean_dnbd3 "$moddir/binaries/dnbd3/" + build_clean_dnbd3 "$moddir/binaries/dnbd3/" fi if [[ -f "$moddir/binaries/systemd-preserve-process-marker/systemd-preserve-process-marker" ]]; then - utils_clean_systemd_preserve_process_marker \ + build_clean_systemd_preserve_process_marker \ "$moddir/binaries/systemd-preserve-process-marker/" fi return 0 @@ -33,13 +33,15 @@ check() { exceptions.activate if [[ ! -f "$moddir/binaries/nbd/nbd.ko" ]]; then - utils_compile_nbd "$moddir/binaries/nbd/" + build_compile_nbd "$moddir/binaries/nbd/" fi - if [[ ! -f "$moddir/binaries/dnbd3/build/dnbd3.ko" || ! -f "$moddir/binaries/dnbd3/build/dnbd3-client" ]]; then - utils_compile_dnbd3 "$moddir/binaries/dnbd3/" + if [[ ! -f "$moddir/binaries/dnbd3/build/dnbd3.ko" ]] || \ + [[ ! -f "$moddir/binaries/dnbd3/build/dnbd3-client" ]] + then + build_compile_dnbd3 "$moddir/binaries/dnbd3/" fi if [[ ! -f "$moddir/binaries/systemd-preserve-process-marker/systemd-preserve-process-marker" ]]; then - utils_compile_systemd_preserve_process_marker \ + build_compile_systemd_preserve_process_marker \ "$moddir/binaries/systemd-preserve-process-marker/" fi @@ -129,13 +131,14 @@ install() { # region scripts - inst "$moddir/scripts/utils.sh" "/usr/lib/utils.sh" - for file in "$moddir/scripts/rebash/"*; do - inst "$file" "/usr/lib/rebash/$(basename $file)" + local file_path + for file_path in "$moddir/scripts/rebash/"*; do + inst "$file_path" "/usr/lib/rebash/$(basename "$file_path")" done # This script is triggered by udev upon finding the right partitions for # persistent sessions. - inst "$moddir/scripts/prepare-persistent-disks" /sbin/prepare-persistent-disks + inst "$moddir/scripts/prepare-persistent-disks" \ + /sbin/prepare-persistent-disks # endregion |
