712866
From cc7d2eeb36a0472ec76b44caa41ebd68fb40b11c Mon Sep 17 00:00:00 2001
712866
From: Harald Hoyer <harald@redhat.com>
712866
Date: Tue, 22 Jul 2014 14:09:06 +0200
712866
Subject: [PATCH] add "--install-optional" and install_optional_items
712866
712866
(cherry picked from commit 54b68829b60bc3f4c28cfca1ab0336584fe1e74c)
712866
---
712866
 dracut-bash-completion.sh         |  4 ++--
712866
 dracut.8.asc                      |  3 +++
712866
 dracut.conf.5.asc                 |  4 ++++
712866
 dracut.conf.d/fedora.conf.example |  2 +-
712866
 dracut.sh                         | 13 +++++++++++++
712866
 5 files changed, 23 insertions(+), 3 deletions(-)
712866
712866
diff --git a/dracut-bash-completion.sh b/dracut-bash-completion.sh
5c6c2a
index 9f359c6e..feced605 100644
712866
--- a/dracut-bash-completion.sh
712866
+++ b/dracut-bash-completion.sh
712866
@@ -40,7 +40,7 @@ _dracut() {
712866
                               --omit-drivers --modules --omit --drivers --filesystems --install
712866
                               --fwdir --libdirs --fscks --add-fstab --mount --device --nofscks
712866
                               --kmoddir --conf --confdir --tmpdir --stdlog --compress --prefix
712866
-                              --kernel-cmdline --sshkey --persistent-policy'
712866
+                              --kernel-cmdline --sshkey --persistent-policy --install-optional'
712866
         )
712866
 
712866
         if __contains_word "$prev" ${OPTS[ARG]}; then
712866
@@ -49,7 +49,7 @@ _dracut() {
712866
                                 comps=$(compgen -d -- "$cur")
712866
                                 compopt -o filenames
712866
                         ;;
712866
-                        -c|--conf|--sshkey|--add-fstab|--add-device|-I|--install)
712866
+                        -c|--conf|--sshkey|--add-fstab|--add-device|-I|--install|--install-optional)
712866
                                 comps=$(compgen -f -- "$cur")
712866
                                 compopt -o filenames
712866
                         ;;
712866
diff --git a/dracut.8.asc b/dracut.8.asc
5c6c2a
index 5f68d16a..8fd863b9 100644
712866
--- a/dracut.8.asc
712866
+++ b/dracut.8.asc
712866
@@ -355,6 +355,9 @@ example:
712866
 ----
712866
 ===============================
712866
 
712866
+**--install-optional** _<file list>_::
712866
+    install the space separated list of files into the initramfs, if they exist.
712866
+
712866
 **--gzip**::
712866
     Compress the generated initramfs using gzip. This will be done by default,
712866
     unless another compression option or --no-compress is passed. Equivalent to
712866
diff --git a/dracut.conf.5.asc b/dracut.conf.5.asc
5c6c2a
index 99f70fff..c20a341d 100644
712866
--- a/dracut.conf.5.asc
712866
+++ b/dracut.conf.5.asc
712866
@@ -66,6 +66,10 @@ Configuration files must have the extension .conf; other extensions are ignored.
712866
 *install_items+=*" __<file>__[ __<file>__ ...] "::
712866
     Specify additional files to include in the initramfs, separated by spaces.
712866
 
712866
+*install_optional_items+=*" __<file>__[ __<file>__ ...] "::
712866
+    Specify additional files to include in the initramfs, separated by spaces,
712866
+    if they exist.
712866
+
712866
 *do_strip=*"__{yes|no}__"::
712866
     Strip binaries in the initramfs (default=yes)
712866
 
712866
diff --git a/dracut.conf.d/fedora.conf.example b/dracut.conf.d/fedora.conf.example
5c6c2a
index ff4e3b27..d69c943b 100644
712866
--- a/dracut.conf.d/fedora.conf.example
712866
+++ b/dracut.conf.d/fedora.conf.example
712866
@@ -6,7 +6,7 @@ i18n_default_font="latarcyrheb-sun16"
712866
 i18n_install_all="yes"
712866
 stdloglvl=3
712866
 sysloglvl=5
712866
-install_items+=" vi /etc/virc ps grep cat rm "
712866
+install_optional_items+=" vi /etc/virc ps grep cat rm "
712866
 prefix="/"
712866
 systemdutildir=/usr/lib/systemd
712866
 systemdsystemunitdir=/usr/lib/systemd/system
712866
diff --git a/dracut.sh b/dracut.sh
5c6c2a
index 78976792..fefdefd5 100755
712866
--- a/dracut.sh
712866
+++ b/dracut.sh
712866
@@ -158,6 +158,8 @@ Creates initial ramdisk images for preloading modules
712866
                          in the final initramfs.
712866
   -I, --install [LIST]  Install the space separated list of files into the
712866
                          initramfs.
712866
+  --install-optional [LIST]  Install the space separated list of files into the
712866
+                         initramfs, if they exist.
712866
   --gzip                Compress the generated initramfs using gzip.
712866
                          This will be done by default, unless another
712866
                          compression option or --no-compress is passed.
712866
@@ -305,6 +307,7 @@ rearrange_params()
712866
         --long drivers: \
712866
         --long filesystems: \
712866
         --long install: \
712866
+        --long install-optional: \
712866
         --long fwdir: \
712866
         --long libdirs: \
712866
         --long fscks: \
712866
@@ -471,6 +474,9 @@ while :; do
712866
         -d|--drivers)  push drivers_l            "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
712866
         --filesystems) push filesystems_l        "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
712866
         -I|--install)  push install_items_l      "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
712866
+        --install-optional)
712866
+                       push install_optional_items_l \
712866
+                                                 "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
712866
         --fwdir)       push fw_dir_l             "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
712866
         --libdirs)     push libdirs_l            "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
712866
         --fscks)       push fscks_l              "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
712866
@@ -722,6 +728,12 @@ if (( ${#install_items_l[@]} )); then
712866
     done
712866
 fi
712866
 
712866
+if (( ${#install_optional_items_l[@]} )); then
712866
+    while pop install_optional_items_l val; do
712866
+        install_optional_items+=" $val "
712866
+    done
712866
+fi
712866
+
712866
 # these options override the stuff in the config file
712866
 if (( ${#dracutmodules_l[@]} )); then
712866
     dracutmodules=''
712866
@@ -1361,6 +1373,7 @@ fi
712866
 
712866
 if [[ $kernel_only != yes ]]; then
712866
     (( ${#install_items[@]} > 0 )) && inst_multiple ${install_items[@]}
712866
+    (( ${#install_optional_items[@]} > 0 )) && inst_multiple -o ${install_optional_items[@]}
712866
 
712866
     [[ $kernel_cmdline ]] && printf "%s\n" "$kernel_cmdline" >> "${initdir}/etc/cmdline.d/01-default.conf"
712866