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