]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
dracut: let some parameters be specified multiple times
authorHarald Hoyer <harald@redhat.com>
Thu, 10 Mar 2011 16:01:10 +0000 (17:01 +0100)
committerHarald Hoyer <harald@redhat.com>
Thu, 10 Mar 2011 16:22:56 +0000 (17:22 +0100)
These parameters can now be specified multiple times:
-a|--add
--add-drivers
-m|--modules
-o|--omit
-d|--drivers
--filesystems
-I|--install
--fwdir
-i|--include

dracut
dracut.8.xml

diff --git a/dracut b/dracut
index a9bc0d03aadd7b17cbcac1e5e8aef8ee13524b6c..4c3394c280a34b0031f33463bef86cc80d65727a 100755 (executable)
--- a/dracut
+++ b/dracut
@@ -151,21 +151,39 @@ read_arg() {
     fi
 }
 
+# Little helper function for reading args from the commandline to a stack.
+# it automatically handles -a b and -a=b variants, and returns 1 if
+# we need to shift $3.
+push_arg() {
+    # $1 = arg name
+    # $2 = arg value
+    # $3 = arg parameter
+    local rematch='^[^=]*=(.*)$'
+    if [[ $2 =~ $rematch ]]; then
+        push "$1" "${BASH_REMATCH[1]}"
+    else
+        push "$1" "$3"
+        # There is no way to shift our callers args, so
+        # return 1 to indicate they should do it instead.
+        return 1
+    fi
+}
+
 kernel="unset"
 
 while (($# > 0)); do
     case ${1%%=*} in
-        -m|--modules)  read_arg dracutmodules_l      "$@" || shift;;
-        -o|--omit)     read_arg omit_dracutmodules_l "$@" || shift;;
-        -a|--add)      read_arg add_dracutmodules_l  "$@" || shift;;
-        -d|--drivers)  read_arg drivers_l            "$@" || shift;;
-        --add-drivers) read_arg add_drivers_l        "$@" || shift;;
-        --filesystems) read_arg filesystems_l        "$@" || shift;;
+        -a|--add)      push_arg add_dracutmodules_l  "$@" || shift;;
+        --add-drivers) push_arg add_drivers_l        "$@" || shift;;
+        -m|--modules)  push_arg dracutmodules_l      "$@" || shift;;
+        -o|--omit)     push_arg omit_dracutmodules_l "$@" || shift;;
+        -d|--drivers)  push_arg drivers_l            "$@" || shift;;
+        --filesystems) push_arg filesystems_l        "$@" || shift;;
+        -I|--install)  push_arg install_items        "$@" || shift;;
+        --fwdir)       push_arg fw_dir_l             "$@" || shift;;
         -k|--kmoddir)  read_arg drivers_dir_l        "$@" || shift;;
         -c|--conf)     read_arg conffile             "$@" || shift;;
         --confdir)     read_arg confdir              "$@" || shift;;
-        -I|--install)  read_arg install_items        "$@" || shift;;
-        --fwdir)       read_arg fw_dir_l             "$@" || shift;;
         -f|--force)    force=yes;;
         --kernel-only) kernel_only="yes"; no_kernel="no";;
         --no-kernel)   kernel_only="no"; no_kernel="yes";;
@@ -181,7 +199,7 @@ while (($# > 0)); do
         -H|--hostonly) hostonly_l="yes" ;;
         --fstab)       use_fstab_l="yes" ;;
         -h|--help)     usage; exit 1 ;;
-        -i|--include)  include_src="$2"; include_target="$3"; shift 2;;
+        -i|--include)  push include_src "$2"; push include_target "$3"; shift 2;;
         --bzip2)       [[ $compress != cat ]] && compress="bzip2 -9";;
         --lzma)          [[ $compress != cat ]] && compress="lzma -9";;
         --no-compress) compress="cat";;
@@ -245,16 +263,55 @@ if [[ $confdir && -d $confdir ]]; then
 fi
 
 # these optins add to the stuff in the config file
-[[ $add_dracutmodules_l ]] && add_dracutmodules+=" $add_dracutmodules_l"
-[[ $add_drivers_l ]] && add_drivers+=" $add_drivers_l"
+if [[ ${#add_dracutmodules_l[@]} ]]; then
+    while pop add_dracutmodules_l val; do
+        add_dracutmodules+=" $val "
+    done
+fi
+
+if [[ ${#add_drivers_l[@]} ]]; then
+    while pop add_drivers_l val; do
+        add_drivers+=" $val "
+    done
+fi
 
 # these options override the stuff in the config file
-[[ $dracutmodules_l ]] && dracutmodules=$dracutmodules_l
-[[ $omit_dracutmodules_l ]] && omit_dracutmodules=$omit_dracutmodules_l
-[[ $drivers_l ]] && drivers=$drivers_l
-[[ $filesystems_l ]] && filesystems=$filesystems_l
+if [[ ${#dracutmodules_l[@]} ]]; then
+    dracutmodules=''
+    while pop dracutmodules_l val; do
+        dracutmodules+="$val "
+    done
+fi
+
+if [[ ${#omit_dracutmodules_l[@]} ]]; then
+    omit_dracutmodules=''
+    while pop omit_dracutmodules_l val; do
+        omit_dracutmodules+="$val "
+    done
+fi
+
+if [[ ${#drivers_l[@]} ]]; then
+    drivers=''
+    while pop drivers_l val; do
+        drivers+="$val "
+    done
+fi
+
+if [[ ${#filesystems_l[@]} ]]; then
+    filesystems=''
+    while pop filesystems_l val; do
+        filesystems+="$val "
+    done
+fi
+
+if [[ ${#fw_dir_l[@]} ]]; then
+    fw_dir=''
+    while pop fw_dir_l val; do
+        fw_dir+="$val "
+    done
+fi
+
 [[ $drivers_dir_l ]] && drivers_dir=$drivers_dir_l
-[[ $fw_dir_l ]] && fw_dir=$fw_dir_l
 [[ $do_strip_l ]] && do_strip=$do_strip_l
 [[ $hostonly_l ]] && hostonly=$hostonly_l
 [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
@@ -397,17 +454,21 @@ if [[ -d $initdir/lib/modules/$kernel ]] && \
     exit 1
 fi
 
-if [[ $include_src && $include_target ]]; then
-    if [[ -f $include_src ]]; then
-        inst $include_src $include_target
-    else
-        mkdir -p "$initdir$include_target"
-        cp -a -t "$initdir$include_target" "$include_src"/*
+while pop include_src src && pop include_target tgt; do
+    if [[ $src && $tgt ]]; then
+        if [[ -f $src ]]; then
+            inst $src $tgt
+        else
+            mkdir -p "${initdir}/${tgt}"
+            cp -a -t "${initdir}/${tgt}" "$src"/*
+        fi
     fi
-fi
+done
 
-for item in $install_items; do
-    dracut_install "$item"
+while pop install_items items; do
+    for item in $items; do
+        dracut_install "$item"
+    done
 done
 unset item
 
index 35e3b119f2612b9bc12570d46a17b7892a36f0a1..05416d184ad518e62ba7855e90c663fe7a6d3e73 100644 (file)
@@ -333,7 +333,7 @@ the local host instead of a generic host.
           </term>
           <listitem>
             <para>include the files in the SOURCE directory into the
-TARGET directory in the final initramfs. If SOURCE is a file, it will be installed to TARGET in the final initramfs.</para>
+TARGET directory in the final initramfs. If SOURCE is a file, it will be installed to TARGET in the final initramfs. This parameter can be specified multiple times.</para>
           </listitem>
         </varlistentry>
         <varlistentry>