Blob Blame History Raw
From cc7d2eeb36a0472ec76b44caa41ebd68fb40b11c Mon Sep 17 00:00:00 2001
From: Harald Hoyer <harald@redhat.com>
Date: Tue, 22 Jul 2014 14:09:06 +0200
Subject: [PATCH] add "--install-optional" and install_optional_items

(cherry picked from commit 54b68829b60bc3f4c28cfca1ab0336584fe1e74c)
---
 dracut-bash-completion.sh         |  4 ++--
 dracut.8.asc                      |  3 +++
 dracut.conf.5.asc                 |  4 ++++
 dracut.conf.d/fedora.conf.example |  2 +-
 dracut.sh                         | 13 +++++++++++++
 5 files changed, 23 insertions(+), 3 deletions(-)

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