diff options
author | torben | 2016-02-05 16:04:01 +0100 |
---|---|---|
committer | torben | 2016-02-05 16:04:01 +0100 |
commit | ee0e8de52ddef4616b14787813f47de54a78502e (patch) | |
tree | ee2eb5f56d75056e38941d9b31bb6570095b174c /builder/build-initramfs.sh | |
parent | update rebash (diff) | |
download | systemd-init-ee0e8de52ddef4616b14787813f47de54a78502e.tar.gz systemd-init-ee0e8de52ddef4616b14787813f47de54a78502e.tar.xz systemd-init-ee0e8de52ddef4616b14787813f47de54a78502e.zip |
Refactoring logging.
Diffstat (limited to 'builder/build-initramfs.sh')
-rwxr-xr-x | builder/build-initramfs.sh | 134 |
1 files changed, 54 insertions, 80 deletions
diff --git a/builder/build-initramfs.sh b/builder/build-initramfs.sh index 550034c8..b023bff6 100755 --- a/builder/build-initramfs.sh +++ b/builder/build-initramfs.sh @@ -57,9 +57,6 @@ core.import change_root # endregion -logging.set_commands_log_level debug -logging.set_log_level critical - # region properties file_path='/boot/initramfs.img' @@ -70,10 +67,10 @@ target='' create_system_image='' cleanup='no' use_systemd_in_initramfs='no' -declare -A dependencies=( +declare -A core_dependencies=( [cpio]='pack initramfs' \ [shift]='parse command line' \ - [mktemp]=create save temporary files and dictionaries \ + [mktemp]='create save temporary files and dictionaries' \ [cat]='print messages' \ [rm]='remove (temporary) files' \ [sed]='process strings' \ @@ -86,9 +83,10 @@ declare -A optional_dependencies=( ['git gzip curl tar']='dynamically retrieve and unpack missing application which will be compiled for current or given kernel' \ ['make gcc cmake']='dynamically compile needed resources against current or given kernel' \ [chroot]='build against a distribution other than this program runs in') -declare -A shared_library_pattern_dependencies=() +declare -A core_shared_library_pattern_dependencies=( + ['TODO libz']='compile dnbd3 for given or current kernel') declare -A optional_shared_library_pattern_dependencies=() -declare -A package_dependencies=() +declare -A core_package_dependencies=() declare -A optional_package_dependencies=( ['fuse glib-2.0 pixman-1']='support template systems in container (usually used by virtual runtime environments)') @@ -98,21 +96,21 @@ declare -A optional_package_dependencies=( ## region command line interface -function print_usage_message() { +print_usage_message() { # Prints a description about how to use this program. logging.cat << EOF This program provides a generic way to install systemd based remote linux initramfs. EOF } -function print_usage_examples() { +print_usage_examples() { # Prints a description about how to use this program by providing examples. logging.cat << EOF Start install progress: >>> ./build_initramfs.sh EOF } -function print_command_line_option_description() { +print_command_line_option_description() { # Prints descriptions about each available command line option. logging.cat << EOF -h --help Shows this help message. @@ -144,7 +142,7 @@ them via a single dash (-) (default: "$dracut_parameter" with concated.). EOF } -function print_help_message() { +print_help_message() { # Provides a help message for this module. logging.plain "\nUsage: $0 [options]\n" print_usage_message "$@" @@ -154,7 +152,7 @@ function print_help_message() { print_command_line_option_description "$@" logging.plain } -function parse_command_line() { +parse_command_line() { # Provides the command line interface and interactive questions. while true; do case "$1" in @@ -227,14 +225,14 @@ function parse_command_line() { esac done if [ "$verbose" == 'yes' ]; then - logging.set_commands_log_level debug - logging.set_log_level info + logging.set_level info fi if [ "$debug" == 'yes' ]; then - logging.set_commands_log_level debug - logging.set_log_level debug + logging.set_level debug fi + return 0 + # TODO This sanity check is only needed for some cli combinations. if [[ "$UID" != '0' ]]; then logging.critical \ "You have to run this script as \"root\" not as \"${USER}\"." @@ -247,7 +245,35 @@ function parse_command_line() { ## region helper -function initialize_dracut() { +dependency_check() { + # Check for given dependencies with given dependency checker and log + # corresponding messages. + local result=0 + eval "local _dependencies=\"\${!${1}_${2}[@]}\"" + + echo + echo $1 $2 $3 + echo + for dependency_group in $_dependencies; do + # NOTE: If "dependency_check_result" would be marked as local it is + # empty later. + dependency_check_result="$($3 $dependency_group)" || \ + local return_code=$? + echo $return_code + if [[ $return_code == 1 ]]; then + echo -n "$dependency_check_result" + elif [[ $return_code == 2 ]]; then + while read dependency; do + eval "local reason=\${${1}${2}[\$dependency_group]}" + logging.critical "Missing $1 dependency \"$dependency\" needed for $reason." + done <<< $dependency_check_result + result=1 + fi + return_code=0 + done + return $result +} +initialize_dracut() { # Downloads and compiles dracut. # # Examples: @@ -275,7 +301,7 @@ function initialize_dracut() { popd return $? } -function cleanup() { +cleanup() { # Removes distribution specific generated files. # # Examples: @@ -294,75 +320,23 @@ function cleanup() { # region controller -## region core dependency checks - -for dependency_group in "${!dependencies[@]}"; do - _result="$(utils.dependency_check $dependency_group || true)" - if [[ "$_result" != '' ]]; then - while read dependency; do - logging.critical "Missing core dependency \"$dependency\" needed for ${dependencies[$dependency_group]}." - done <<< $_result - fi -done -for dependency_group in "${!shared_library_pattern_dependencies[@]}"; do - _result="$(utils.dependency_check_shared_library $dependency_group || true)" - if [[ "$_result" != '' ]]; then - while read dependency; do - logging.critical "Missing core shared library dependency \"$dependency\" needed for ${shared_library_pattern_dependencies[$dependency_group]}." - done <<< $_result - fi -done -for dependency_group in "${!package_dependencies[@]}"; do - _result="$(utils.dependency_check_pkgconfig $dependency_group || true)" - if [[ "$_result" != '' ]]; then - while read dependency; do - logging.critical "Missing core package dependency \"$dependency\" needed for ${package_dependencies[$dependency_group]}." - done <<< $_result - fi -done - -# TODO check for existing kernel headers. -# Find lib locations: $(gcc -print-prog-name=cc1plus) -v -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 +#dependency_check core dependencies utils_dependency_check +dependency_check core shared_library_pattern_dependencies \ + utils_dependency_check_shared_library +dependency_check core package_dependencies utils_dependency_check_pkgconfig -## endregion +logging.set_commands_level debug if ! parse_command_line "$@"; then print_help_message "$0" exit 1 fi -## region optional dependency checks - -for dependency_group in "${!optional_dependencies[@]}"; do - _result="$(utils.dependency_check $dependency_group || true)" - if [[ "$_result" != '' ]]; then - while read dependency; do - logging.warn "Missing optional dependency \"$dependency\" needed for ${optional_dependencies[$dependency_group]}." - done <<< $_result - fi -done -for dependency_group in "${!optional_shared_library_pattern_dependencies[@]}"; do - _result="$(utils.dependency_check_shared_library $dependency_group || true)" - if [[ "$_result" != '' ]]; then - while read dependency; do - logging.critical "Missing optional shared library dependency \"$dependency\" needed for ${optional_shared_library_pattern_dependencies[$dependency_group]}." - done <<< $_result - fi -done -for dependency_group in "${!optional_package_dependencies[@]}"; do - _result="$(utils.dependency_check_pkgconfig $dependency_group || true)" - if [[ "$_result" != '' ]]; then - while read dependency; do - logging.critical "Missing optional package dependency \"$dependency\" needed for ${optional_package_dependencies[$dependency_group]}." - done <<< $_result - fi -done - -## endregion +dependency_check optional dependencies utils_dependency_check +dependency_check optional shared_library_pattern_dependencies \ + utils_dependency_check_shared_library +dependency_check optional package_dependencies utils_dependency_check_pkgconfig +exit 0 ## region handle delegated operations to specified target |