diff options
Diffstat (limited to 'builder/build-initramfs.sh')
-rwxr-xr-x | builder/build-initramfs.sh | 170 |
1 files changed, 131 insertions, 39 deletions
diff --git a/builder/build-initramfs.sh b/builder/build-initramfs.sh index 710676a5..c05694d1 100755 --- a/builder/build-initramfs.sh +++ b/builder/build-initramfs.sh @@ -65,7 +65,6 @@ dracut_parameter='--force --no-hostonly' verbose='no' debug='no' target='' -create_system_image='' cleanup='no' full_cleanup='no' use_systemd_in_initramfs='no' @@ -96,21 +95,33 @@ declare -A optional_package_dependencies=( # region functions ## region command line interface print_usage_message() { - # Prints a description about how to use this program. + local __doc__=' + Prints a description about how to use this program. + + >>> print_usage_message &>/dev/null + ' logging.cat << EOF This program provides a generic way to install systemd based remote linux initramfs. EOF } print_usage_examples() { - # Prints a description about how to use this program by providing examples. + local __doc__=' + Prints a description about how to use this program by providing examples. + + >>> print_usage_examples &>/dev/null + ' logging.cat << EOF Start install progress: >>> ./build_initramfs.sh EOF } print_command_line_option_description() { - # Prints descriptions about each available command line option. + local __doc__=' + Prints descriptions about each available command line option. + + >>> print_command_line_option_description &>/dev/null + ' logging.cat << EOF -h --help Shows this help message. @@ -126,9 +137,6 @@ print_command_line_option_description() { -f --full-cleanup Removes all retrieved and compiled files (usefull to retrieve latest version of all nested modules). --i --create-system-image Creates an image under given path from current system. - (default: "$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: "$target"). @@ -144,7 +152,11 @@ concatenated.). EOF } print_help_message() { - # Provides a help message for this module. + local __doc__=' + Provides a help message for this module. + + >>> print_help_message &>/dev/null + ' logging.plain "\nUsage: $0 [options]\n" print_usage_message "$@" logging.plain '\nExamples:\n' @@ -154,7 +166,91 @@ print_help_message() { logging.plain } parse_command_line() { - # Provides the command line interface and interactive questions. + local __doc__=' + Provides the command line interface and interactive questions. + + >>> parse_command_line -h &>/dev/null + + >>> echo "$verbose" + no + >>> logging.get_level + critical + >>> parse_command_line -v + >>> echo "$verbose" + >>> logging.get_level + yes + info + + >>> echo "$debug" + no + >>> parse_command_line --debug + >>> echo "$debug" + >>> logging.get_level + yes + debug + + >>> parse_command_line -p; echo $? + +doc_test_contains + Error with given option "-p": + +doc_test_ellipsis + Traceback (most recent call first): + ... + + >>> echo "$file_path" + /boot/initramfs.img + >>> parse_command_line -p /tmp/test.img + >>> echo "$file_path" + /tmp/test.img + + >>> echo "$cleanup" + no + >>> parse_command_line --cleanup + >>> echo "$cleanup" + yes + + >>> echo "$full_cleanup" + no + >>> parse_command_line --full-cleanup + >>> echo "$full_cleanup" + yes + + >>> echo "$full_cleanup" + no + >>> parse_command_line --full-cleanup + >>> echo "$full_cleanup" + yes + + >>> echo "$use_systemd_in_initramfs" + no + >>> parse_command_line -s + >>> echo "$use_systemd_in_initramfs" + yes + + >>> parse_command_line -t; echo $? + +doc_test_contains + Error with given option "-t": + +doc_test_ellipsis + Traceback (most recent call first): + ... + + >>> [[ "$target" = "" ]] + >>> parse_command_line -t /tmp/ + >>> echo "$target" + /tmp/ + + >>> echo "$dracut_parameter" + --force --no-hostonly + >>> parse_command_line - --test + >>> echo "$dracut_parameter" + --force --no-hostonly --test + + >>> parse_command_line --no-available-option; echo $? + +doc_test_contains + Error with given option "--no-available-option": + +doc_test_ellipsis + Traceback (most recent call first): + ... + ' while true; do case "$1" in -h|--help) @@ -175,7 +271,7 @@ parse_command_line() { file_path="$1" if [[ "$file_path" == '' ]]; then logging.critical \ - "This options needs a path to save initramfs image to." + "Error with given option "$1": This option needs a path to save initramfs image to." return 1 fi shift @@ -192,22 +288,12 @@ parse_command_line() { shift use_systemd_in_initramfs='yes' ;; - -i|--create-system-image) - shift - create_system_image="$1" - if [[ "$create_system_image" == '' ]]; then - logging.critical \ - "This options needs a path to save image to." - return 1 - fi - shift - ;; -t|--target) shift target="$1" if [[ "$target" == '' ]]; then logging.critical \ - "This options needs a path create initramfs from." + "Error with given option "$1": This option needs a path create initramfs from." return 1 fi shift @@ -225,7 +311,7 @@ parse_command_line() { break ;; *) - logging.critical "Given argument: \"$1\" is not available." + logging.critical "Error with given option "$1": This argument is not available." return 1 esac done @@ -247,8 +333,14 @@ parse_command_line() { ## endregion ## region helper dependency_check() { - # Check for given dependencies with given dependency checker and log - # corresponding messages. + __doc__=' + Check for given dependencies with given dependency checker and log + corresponding messages. + + Example: + + dependency_check core dependencies utils_dependency_check program + ' local result=0 eval 'for dependency_group in "${!'$1'_'$2'[@]}"; do @@ -276,12 +368,13 @@ dependency_check() { return $result } initialize_dracut() { - # Downloads and compiles dracut. - # - # Examples: - # - # >>> initialize_dracut - # ... + __doc__=' + Downloads and compiles dracut. + + Example: + + initialize_dracut + ' if [[ ! -f "$(dirname "${BASH_SOURCE[0]}")/dracut/install/dracut-install" ]] then mkdir --parents "$(dirname "${BASH_SOURCE[0]}")/dracut" @@ -307,11 +400,13 @@ initialize_dracut() { return $? } cleanup() { - # Removes distribution specific generated files. - # - # Examples: - # - # >>> cleanup + __doc__=' + Removes distribution specific generated files. + + Example: + + cleanup + ' local plugin_path="$(dirname "${BASH_SOURCE[0]}")/dnbd3-rootfs/" source "${plugin_path}module-setup.sh" moddir="$(cd "$plugin_path" &>/dev/null && pwd)" @@ -443,10 +538,7 @@ fi if [ "$use_systemd_in_initramfs" == 'yes' ]; then _modules="$_modules systemd systemd-initrd dracut-systemd" fi -if [[ "$create_system_image" != '' ]]; then - logging.info 'Create system image.' - create_qcow2_system "$create_system_image" -elif [[ "$full_cleanup" == 'yes' ]]; then +if [[ "$full_cleanup" == 'yes' ]]; then logging.info 'Removing all modules.' rm "$(dirname "${BASH_SOURCE[0]}")/dnbd3-rootfs" \ "$(dirname "${BASH_SOURCE[0]}")/dracut" --recursive --force |