From 5547a5effe092e3d344713c3f1e9e7fd8e34114e Mon Sep 17 00:00:00 2001 From: Jonathan Bauer Date: Wed, 13 May 2020 13:55:01 +0200 Subject: build-initramfs.sh: vim retab --- build-initramfs.sh | 452 ++++++++++++++++++++++++++--------------------------- 1 file changed, 226 insertions(+), 226 deletions(-) (limited to 'build-initramfs.sh') diff --git a/build-initramfs.sh b/build-initramfs.sh index ae8384ff..d2876366 100755 --- a/build-initramfs.sh +++ b/build-initramfs.sh @@ -2,9 +2,9 @@ # -*- coding: utf-8 -*- # region header # Copyright Torben Sickert (info["~at~"]torben.website) 29.10.2015 -# Janosch Dobler (info["~at~"]jandob.com) 29.10.2015 -# Jonathan Bauer (jonathan.bauer@rz.uni-freiburg.de) 19.09.2019 -# Thiago Abdo (tjabdo@inf.ufpr.br) 06.11.2019 +# Janosch Dobler (info["~at~"]jandob.com) 29.10.2015 +# Jonathan Bauer (jonathan.bauer@rz.uni-freiburg.de) 19.09.2019 +# Thiago Abdo (tjabdo@inf.ufpr.br) 06.11.2019 # License # ------- @@ -15,10 +15,10 @@ # Afaik the idea here was to have the root dir where build-initramfs.sh # is called from and the repo dir where the systemd-init.git is cloned to: -# -# |- build-initramfs.sh -# |- dracut -# |- systemd-init +# +# |- build-initramfs.sh +# |- dracut +# |- systemd-init declare -rg _root_dir="$(readlink -f $(dirname ${BASH_SOURCE[0]}))" # TODO clean these up @@ -53,7 +53,7 @@ bootstrap() { echo "Modules file: $_bootstrap_modules" echo "Core modules: ${!core_*}" - echo "Modules: ${!module_*}" + echo "Modules: ${!module_*}" echo "" @@ -65,10 +65,10 @@ bootstrap() { fi echo "######################### $module #########################" echo "Handler: ${_ref[handler]}" - echo " URL: ${_ref[url]}" + echo " URL: ${_ref[url]}" echo " Branch: ${_ref[branch]}" echo " Commit: ${_ref[commit]}" - echo " Path: ${_ref[path]}" + echo " Path: ${_ref[path]}" handler_${_ref[handler]} \ "${_ref[path]}" \ "${_ref[url]}" \ @@ -148,245 +148,245 @@ print_help_message() { } parse_command_line() { - while true; do - case "$1" in - -h|--help) - shift - print_help_message "$0" - exit 0 - ;; - -v|--verbose) - shift - verbose='yes' - ;; - -d|--debug) - shift - debug='yes' - ;; - -p|--file-path) - local given_argument="$1" - shift - file_path="$1" - if [[ "$file_path" == '' ]]; then - echo \ - "Error with given option \"$given_argument\": This option needs a path to save initramfs image to." - return 1 - fi - shift - ;; - -c|--cleanup) - shift - cleanup='yes' - ;; - -f|--full-cleanup) - shift - full_cleanup='yes' - ;; - -s|--use-systemd-in-initramfs) - shift - use_systemd_in_initramfs='yes' - ;; - -t|--target) - local given_argument="$1" - shift - target="$1" - if [[ "$target" == '' ]]; then - echo \ - "Error with given option \"$given_argument\": This option needs a path create initramfs from." - return 1 - fi - shift - ;; - -i|--init) - shift - initialize='yes' - ;; - -k|--kernel-version) - local given_argument="$1" - shift - kernel_version="$1" - if [ -z "$kernel_version" ]; then - echo \ - "Error with given option \"$given_argument\": This option needs a kernel version to build the initramfs for." - return 1 - fi - shift - ;; - -H|--kernel-headers) - local given_argument="$1" - shift - kernel_headers="$1" - if [ -z "$kernel_headers" ]; then - echo \ - "Error with given option \"$given_argument\": This option needs the path to the kernel headers." - return 1 - fi - shift - ;; - -q|--qcow-handler) - local given_argument="$1" - shift - qcow_handler="$1" - if [ -z "$qcow_handler" ]; then - echo \ - "Error with given option \"$given_argument\": This options needs to be either 'xmount' or 'kernel'." - return 1 - fi - shift - ;; - -u|--update) - shift - update='yes' - ;; - -) - shift - while [[ "$1" =~ ^.+$ ]]; do - dracut_parameter+=("$1") - shift - done - ;; - '') - break - ;; - *) - echo \ - "Error with given option \"$1\": This argument is not available." - return 1 - esac - done + while true; do + case "$1" in + -h|--help) + shift + print_help_message "$0" + exit 0 + ;; + -v|--verbose) + shift + verbose='yes' + ;; + -d|--debug) + shift + debug='yes' + ;; + -p|--file-path) + local given_argument="$1" + shift + file_path="$1" + if [[ "$file_path" == '' ]]; then + echo \ + "Error with given option \"$given_argument\": This option needs a path to save initramfs image to." + return 1 + fi + shift + ;; + -c|--cleanup) + shift + cleanup='yes' + ;; + -f|--full-cleanup) + shift + full_cleanup='yes' + ;; + -s|--use-systemd-in-initramfs) + shift + use_systemd_in_initramfs='yes' + ;; + -t|--target) + local given_argument="$1" + shift + target="$1" + if [[ "$target" == '' ]]; then + echo \ + "Error with given option \"$given_argument\": This option needs a path create initramfs from." + return 1 + fi + shift + ;; + -i|--init) + shift + initialize='yes' + ;; + -k|--kernel-version) + local given_argument="$1" + shift + kernel_version="$1" + if [ -z "$kernel_version" ]; then + echo \ + "Error with given option \"$given_argument\": This option needs a kernel version to build the initramfs for." + return 1 + fi + shift + ;; + -H|--kernel-headers) + local given_argument="$1" + shift + kernel_headers="$1" + if [ -z "$kernel_headers" ]; then + echo \ + "Error with given option \"$given_argument\": This option needs the path to the kernel headers." + return 1 + fi + shift + ;; + -q|--qcow-handler) + local given_argument="$1" + shift + qcow_handler="$1" + if [ -z "$qcow_handler" ]; then + echo \ + "Error with given option \"$given_argument\": This options needs to be either 'xmount' or 'kernel'." + return 1 + fi + shift + ;; + -u|--update) + shift + update='yes' + ;; + -) + shift + while [[ "$1" =~ ^.+$ ]]; do + dracut_parameter+=("$1") + shift + done + ;; + '') + break + ;; + *) + echo \ + "Error with given option \"$1\": This argument is not available." + return 1 + esac + done - return 0 + return 0 } ## endregion ## region helper compile_dracut() { - pushd "${_dracut_dir}" - # NOTE: On virtualbox shared folder symlinks are not allowed. - # NOTE: make the dracut-install binary (dracut-install resolves - # dependencies etc.) - echo 'Compiling dracut.' - ./configure - make install/dracut-install - # NOTE: We have to copy the binary to current instead of symlinking - # them since this feature isn't supported in shared virtual box machine - # folders. - # If symlinks would be available we could simply use: - # >>> make dracut-install - popd - cp "${_dracut_dir}/install/dracut-install" \ - "${_dracut_dir}/dracut-install" - return $? + pushd "${_dracut_dir}" + # NOTE: On virtualbox shared folder symlinks are not allowed. + # NOTE: make the dracut-install binary (dracut-install resolves + # dependencies etc.) + echo 'Compiling dracut.' + ./configure + make install/dracut-install + # NOTE: We have to copy the binary to current instead of symlinking + # them since this feature isn't supported in shared virtual box machine + # folders. + # If symlinks would be available we could simply use: + # >>> make dracut-install + popd + cp "${_dracut_dir}/install/dracut-install" \ + "${_dracut_dir}/dracut-install" + return $? } # The idea here was to source each module-setup.sh from our # custom dracut modules and call their clean() function. # TODO: Does this still work? cleanup() { - local plugin_path - plugin_path="${_repo_dir}/modules.d/dnbd3-rootfs" - source "${plugin_path}/module-setup.sh" - moddir="$(cd "$plugin_path" &>/dev/null && pwd)" - clean - return $? + local plugin_path + plugin_path="${_repo_dir}/modules.d/dnbd3-rootfs" + source "${plugin_path}/module-setup.sh" + moddir="$(cd "$plugin_path" &>/dev/null && pwd)" + clean + return $? } main() { - if ! parse_command_line "$@"; then - print_help_message "$0" - exit 1 - fi - # prepare submodules for the dnbd3-rootfs module - bootstrap - # if no kernel was specified as dracut argument, use the running kernel's version - echo "Building for:" - if [ -z "$kernel_version" ]; then - kernel_version="$(uname -r)" - fi - echo " * kernel version: $kernel_version" - # similar for kernel headers needed to compile dnbd3 against. - if [ -z "$kernel_headers" ]; then - kernel_headers="/lib/modules/${kernel_version}/build" - fi - if [ ! -f "${kernel_headers}/Makefile" ]; then - echo 'Missing core dependency "linux-headers" for version to compile against given or current kernel.' - fi - echo " * kernel headers: $kernel_headers" - [ -n "$qcow_handler" ] && echo " * qcow2 handler: $qcow_handler" - export _QCOW_HANDLER="$qcow_handler" + if ! parse_command_line "$@"; then + print_help_message "$0" + exit 1 + fi + # prepare submodules for the dnbd3-rootfs module + bootstrap + # if no kernel was specified as dracut argument, use the running kernel's version + echo "Building for:" + if [ -z "$kernel_version" ]; then + kernel_version="$(uname -r)" + fi + echo " * kernel version: $kernel_version" + # similar for kernel headers needed to compile dnbd3 against. + if [ -z "$kernel_headers" ]; then + kernel_headers="/lib/modules/${kernel_version}/build" + fi + if [ ! -f "${kernel_headers}/Makefile" ]; then + echo 'Missing core dependency "linux-headers" for version to compile against given or current kernel.' + fi + echo " * kernel headers: $kernel_headers" + [ -n "$qcow_handler" ] && echo " * qcow2 handler: $qcow_handler" + export _QCOW_HANDLER="$qcow_handler" - if [ "$update" == "yes" ]; then - pushd "${_repo_dir}" - git pull - popd - fi + if [ "$update" == "yes" ]; then + pushd "${_repo_dir}" + git pull + popd + fi echo 'Checking dracut...' - if [ ! -f "${_dracut_dir}/dracut-install" ]; then - echo "Dracut isn't available yet loading it." - compile_dracut - fi + if [ ! -f "${_dracut_dir}/dracut-install" ]; then + echo "Dracut isn't available yet loading it." + compile_dracut + fi - for _dracut_module_dir in "${_repo_dir}/modules.d/"*; do - [ -d "${_dracut_module_dir}" ] || continue - _dracut_module="$(basename $_dracut_module_dir)" - # TODO allow module-specific priority - _dracut_module_target="${_dracut_dir}/modules.d/00${_dracut_module}" - if [[ ! -L "$_dracut_module_target" || "$(readlink \ - "$_dracut_module_target")" != "$_dracut_module_dir" ]]; then - echo \ - "Link ${_dracut_module} plugin into dracut modules folder ($_dracut_module_dir -> $_dracut_module_target)." - if ! ln --symbolic --force "$_dracut_module_dir" "$_dracut_module_target"; then - echo \ - "Linking \"$_dracut_module_dir\" to \"$_dracut_module_target\" failed." \ - " We will copy them. So we have to recopy it every time to ensure that recompiled things take effect." - cp --recursive --force --no-target-directory \ - "$_dracut_module_dir" \ - "$_dracut_module_target" - fi - fi - done + for _dracut_module_dir in "${_repo_dir}/modules.d/"*; do + [ -d "${_dracut_module_dir}" ] || continue + _dracut_module="$(basename $_dracut_module_dir)" + # TODO allow module-specific priority + _dracut_module_target="${_dracut_dir}/modules.d/00${_dracut_module}" + if [[ ! -L "$_dracut_module_target" || "$(readlink \ + "$_dracut_module_target")" != "$_dracut_module_dir" ]]; then + echo \ + "Link ${_dracut_module} plugin into dracut modules folder ($_dracut_module_dir -> $_dracut_module_target)." + if ! ln --symbolic --force "$_dracut_module_dir" "$_dracut_module_target"; then + echo \ + "Linking \"$_dracut_module_dir\" to \"$_dracut_module_target\" failed." \ + " We will copy them. So we have to recopy it every time to ensure that recompiled things take effect." + cp --recursive --force --no-target-directory \ + "$_dracut_module_dir" \ + "$_dracut_module_target" + fi + fi + done - _loglevel='' - if [ "$verbose" == 'yes' ]; then - _loglevel='--verbose' - fi - _modules=(dnbd3-rootfs conf-tgz) - echo "Default modules: ${_modules[@]}" - if [ "$debug" == 'yes' ]; then - _loglevel="$_loglevel --stdlog 4" - _modules+=(i18n terminfo) - fi - if [ "$use_systemd_in_initramfs" == 'yes' ]; then - _modules+=(systemd systemd-initrd dracut-systemd) - fi - # Preprocess done - start build, cleanup or full cleanup - if [[ "$full_cleanup" == 'yes' ]]; then - echo 'Removing all modules.' - rm "${_repo_dir}" "${_dracut_dir}" --recursive --force - elif [[ "$cleanup" == 'yes' ]]; then - echo 'Removing distribution specific files.' - cleanup - else - . "${_repo_dir}/modules.d/dnbd3-rootfs/helper/build.inc" - build_initialize_components + _loglevel='' + if [ "$verbose" == 'yes' ]; then + _loglevel='--verbose' + fi + _modules=(dnbd3-rootfs conf-tgz) + echo "Default modules: ${_modules[@]}" + if [ "$debug" == 'yes' ]; then + _loglevel="$_loglevel --stdlog 4" + _modules+=(i18n terminfo) + fi + if [ "$use_systemd_in_initramfs" == 'yes' ]; then + _modules+=(systemd systemd-initrd dracut-systemd) + fi + # Preprocess done - start build, cleanup or full cleanup + if [[ "$full_cleanup" == 'yes' ]]; then + echo 'Removing all modules.' + rm "${_repo_dir}" "${_dracut_dir}" --recursive --force + elif [[ "$cleanup" == 'yes' ]]; then + echo 'Removing distribution specific files.' + cleanup + else + . "${_repo_dir}/modules.d/dnbd3-rootfs/helper/build.inc" + build_initialize_components if [[ "$initialize" == 'yes' ]]; then echo "Initialized." exit 0 - fi - echo 'Build initramfs.' + fi + echo 'Build initramfs.' - "${_dracut_dir}/dracut.sh" --local \ - $_loglevel --modules "${_modules[*]}" --conf /etc/dracut.conf \ - --confdir /etc/dracut.conf.d "${dracut_parameter[@]}" \ - --kver "${kernel_version}" "$file_path" - _return_code=$? - if [ "$_return_code" != 0 ]; then - echo 'Building initial ram file system failed.' - exit 1 - fi - # NOTE: dracut generate the initramfs with 0600 permissions - chmod 0644 "${file_path}" - fi + "${_dracut_dir}/dracut.sh" --local \ + $_loglevel --modules "${_modules[*]}" --conf /etc/dracut.conf \ + --confdir /etc/dracut.conf.d "${dracut_parameter[@]}" \ + --kver "${kernel_version}" "$file_path" + _return_code=$? + if [ "$_return_code" != 0 ]; then + echo 'Building initial ram file system failed.' + exit 1 + fi + # NOTE: dracut generate the initramfs with 0600 permissions + chmod 0644 "${file_path}" + fi } main "$@" -- cgit v1.2.3-55-g7522