From 24b31716778e20adf4251eb095c57bcb56788b8c Mon Sep 17 00:00:00 2001 From: Simon Rettberg Date: Wed, 20 Oct 2021 11:03:31 +0200 Subject: Simplify cmdline parsing, check qcow handler, don't build unused one --- build-initramfs.sh | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) diff --git a/build-initramfs.sh b/build-initramfs.sh index b00839df..e4b213f6 100755 --- a/build-initramfs.sh +++ b/build-initramfs.sh @@ -61,8 +61,8 @@ declare -A module_dnbd3=( declare -A module_xloop=( [handler]="git" - [url]="git://git.openslx.org/openslx-ng/xloop.git" [path]="${_repo_dir}/modules.d/dnbd3-rootfs/binaries/xloop" + [url]="git://git.openslx.org/openslx-ng/xloop.git" ) declare -A module_qemu_xmount=( @@ -219,16 +219,13 @@ 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) @@ -241,18 +238,14 @@ parse_command_line() { "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) @@ -265,10 +258,8 @@ parse_command_line() { "This option needs a path create initramfs from." return 1 fi - shift ;; -i|--init) - shift initialize='yes' ;; -k|--kernel-version) @@ -281,7 +272,6 @@ parse_command_line() { "This option needs a kernel version to build the initramfs for." return 1 fi - shift ;; -H|--kernel-headers) local given_argument="$1" @@ -293,22 +283,13 @@ parse_command_line() { "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' ;; -O|--override-module) @@ -328,16 +309,10 @@ parse_command_line() { override_argument="|${override_argument}" fi override["$override_module"]+="$override_argument" - shift ;; -) shift - while [[ "$1" =~ ^.+$ ]]; do - dracut_parameter+=("$1") - shift - done - ;; - '') + dracut_parameter+=( "$@" ) break ;; *) @@ -345,8 +320,20 @@ parse_command_line() { "Error with given option \"$1\": This argument is not available." return 1 esac + shift done + if [ "$qcow_handler" = "xmount" ]; then + unset module_xloop + elif [ "$qcow_handler" = "xloop" ]; then + unset module_xmount + else + echo \ + "Error with given option '--qcow-handler/-q':" \ + "This options needs to be either 'xmount' or 'xloop', given: '$qcow_handler'." + return 1 + fi + return 0 } ## endregion -- cgit v1.2.3-55-g7522