Harald Hoyer 55891e
From c32bda6bb9ae085116dc071087afc0431e51a5fb Mon Sep 17 00:00:00 2001
Harald Hoyer 55891e
From: Michal Soltys <soltys@ziu.info>
Harald Hoyer 55891e
Date: Mon, 10 Oct 2011 23:58:04 +0200
Harald Hoyer 55891e
Subject: [PATCH] bash3 compat patch
Harald Hoyer 55891e
Harald Hoyer 55891e
This patch replaces:
Harald Hoyer 55891e
Harald Hoyer 55891e
- {var}>... redirections with functionally identical eval construct +
Harald Hoyer 55891e
  explicit FDs
Harald Hoyer 55891e
- ^^ and ,, case modifiers with temporary shopt
Harald Hoyer 55891e
Harald Hoyer 55891e
This allows us to lower minimum required bash version
Harald Hoyer 55891e
to at least 3.1 (with current code).
Harald Hoyer 55891e
Harald Hoyer 55891e
Signed-off-by: Michal Soltys <soltys@ziu.info>
Harald Hoyer 55891e
---
Harald Hoyer 55891e
 dracut-functions                           |   11 +++++++----
Harald Hoyer 55891e
 modules.d/10i18n/module-setup.sh           |    8 +++++---
Harald Hoyer 55891e
 modules.d/40network/module-setup.sh        |   19 ++++++++++++-------
Harald Hoyer 55891e
 modules.d/90kernel-modules/module-setup.sh |   19 ++++++++++++-------
Harald Hoyer 55891e
 4 files changed, 36 insertions(+), 21 deletions(-)
Harald Hoyer 55891e
Harald Hoyer 55891e
diff --git a/dracut-functions b/dracut-functions
Harald Hoyer 55891e
index ce593c9..1ef5269 100755
Harald Hoyer 55891e
--- a/dracut-functions
Harald Hoyer 55891e
+++ b/dracut-functions
Harald Hoyer 55891e
@@ -821,10 +821,11 @@ install_kmod_with_fw() {
Harald Hoyer 55891e
 #      It will be passed the full path to the found kernel module
Harald Hoyer 55891e
 # $2 = module to get dependencies for
Harald Hoyer 55891e
 # rest of args = arguments to modprobe
Harald Hoyer 55891e
+# _fderr specifies FD passed from surrounding scope
Harald Hoyer 55891e
 for_each_kmod_dep() {
Harald Hoyer 55891e
     local _func=$1 _kmod=$2 _cmd _modpath _options _found=0
Harald Hoyer 55891e
     shift 2
Harald Hoyer 55891e
-    modprobe "$@" --ignore-install --show-depends $_kmod 2>&$modprobe_stderr | (
Harald Hoyer 55891e
+    modprobe "$@" --ignore-install --show-depends $_kmod 2>&${_fderr} | (
Harald Hoyer 55891e
         while read _cmd _modpath _options; do
Harald Hoyer 55891e
             [[ $_cmd = insmod ]] || continue
Harald Hoyer 55891e
             $_func ${_modpath} || exit $?
Harald Hoyer 55891e
@@ -885,6 +886,8 @@ find_kernel_modules () {
Harald Hoyer 55891e
 # install kernel modules along with all their dependencies.
Harald Hoyer 55891e
 instmods() {
Harald Hoyer 55891e
     [[ $no_kernel = yes ]] && return
Harald Hoyer 55891e
+    # called [sub]functions inherit _fderr
Harald Hoyer 55891e
+    local _fderr=9
Harald Hoyer 55891e
 
Harald Hoyer 55891e
     function inst1mod() {
Harald Hoyer 55891e
         local _mod="$1"
Harald Hoyer 55891e
@@ -949,9 +952,9 @@ instmods() {
Harald Hoyer 55891e
         return $_ret
Harald Hoyer 55891e
     }
Harald Hoyer 55891e
 
Harald Hoyer 55891e
-    # Capture all stderr from modprobe onto a new fd $modprobe_stderr,
Harald Hoyer 55891e
-    # and pipe it into egrep.  See REDIRECTION in bash manpage.
Harald Hoyer 55891e
-    ( instmods_1 "$@" ) {modprobe_stderr}>&1 \
Harald Hoyer 55891e
+    # Capture all stderr from modprobe to _fderr. We could use {var}>...
Harald Hoyer 55891e
+    # redirections, but that would make dracut require bash4 at least.
Harald Hoyer 55891e
+    eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
Harald Hoyer 55891e
     | egrep -v 'FATAL: Module .* not found.' | derror
Harald Hoyer 55891e
     return $?
Harald Hoyer 55891e
 }
Harald Hoyer 55891e
diff --git a/modules.d/10i18n/module-setup.sh b/modules.d/10i18n/module-setup.sh
Harald Hoyer 55891e
index 5c09100..6248607 100755
Harald Hoyer 55891e
--- a/modules.d/10i18n/module-setup.sh
Harald Hoyer 55891e
+++ b/modules.d/10i18n/module-setup.sh
Harald Hoyer 55891e
@@ -150,22 +150,24 @@ install() {
Harald Hoyer 55891e
             inst_simple ${kbddir}/unimaps/${FONT_UNIMAP}.uni
Harald Hoyer 55891e
         fi
Harald Hoyer 55891e
 
Harald Hoyer 55891e
+        shopt -q -s nocasematch
Harald Hoyer 55891e
         if [[ ${UNICODE} ]]
Harald Hoyer 55891e
         then
Harald Hoyer 55891e
-            if [[ ${UNICODE^^} = YES || ${UNICODE} = 1 ]]
Harald Hoyer 55891e
+            if [[ ${UNICODE} = YES || ${UNICODE} = 1 ]]
Harald Hoyer 55891e
             then
Harald Hoyer 55891e
                 UNICODE=1
Harald Hoyer 55891e
-            elif [[ ${UNICODE^^} = NO || ${UNICODE} = 0 ]]
Harald Hoyer 55891e
+            elif [[ ${UNICODE} = NO || ${UNICODE} = 0 ]]
Harald Hoyer 55891e
             then
Harald Hoyer 55891e
                 UNICODE=0
Harald Hoyer 55891e
             else
Harald Hoyer 55891e
                 UNICODE=''
Harald Hoyer 55891e
             fi
Harald Hoyer 55891e
         fi
Harald Hoyer 55891e
-        if [[ ! ${UNICODE} && ${LANG^^} =~ .*\.UTF-?8 ]]
Harald Hoyer 55891e
+        if [[ ! ${UNICODE} && ${LANG} =~ .*\.UTF-?8 ]]
Harald Hoyer 55891e
         then
Harald Hoyer 55891e
             UNICODE=1
Harald Hoyer 55891e
         fi
Harald Hoyer 55891e
+        shopt -q -u nocasematch
Harald Hoyer 55891e
 
Harald Hoyer 55891e
         mksubdirs ${initdir}${I18N_CONF}
Harald Hoyer 55891e
         mksubdirs ${initdir}${VCONFIG_CONF}
Harald Hoyer 55891e
diff --git a/modules.d/40network/module-setup.sh b/modules.d/40network/module-setup.sh
Harald Hoyer 55891e
index 03684f1..eb7ef9b 100755
Harald Hoyer 55891e
--- a/modules.d/40network/module-setup.sh
Harald Hoyer 55891e
+++ b/modules.d/40network/module-setup.sh
Harald Hoyer 55891e
@@ -27,6 +27,8 @@ installkernel() {
Harald Hoyer 55891e
     net_module_filter() {
Harald Hoyer 55891e
         local _net_drivers='eth_type_trans|register_virtio_device'
Harald Hoyer 55891e
         local _unwanted_drivers='/(wireless|isdn|uwb)/'
Harald Hoyer 55891e
+        # subfunctions inherit following FDs
Harald Hoyer 55891e
+        local _merge=8 _side2=9
Harald Hoyer 55891e
         function nmf1() {
Harald Hoyer 55891e
             local _fname _fcont
Harald Hoyer 55891e
             while read _fname; do
Harald Hoyer 55891e
@@ -40,14 +42,17 @@ installkernel() {
Harald Hoyer 55891e
                 && echo "$_fname"
Harald Hoyer 55891e
             done
Harald Hoyer 55891e
         }
Harald Hoyer 55891e
+        function rotor() {
Harald Hoyer 55891e
+            local _f1 _f2
Harald Hoyer 55891e
+            while read _f1; do
Harald Hoyer 55891e
+                echo "$_f1"
Harald Hoyer 55891e
+                if read _f2; then
Harald Hoyer 55891e
+                    echo "$_f2" 1>&${_side2}
Harald Hoyer 55891e
+                fi
Harald Hoyer 55891e
+            done | nmf1 1>&${_merge}
Harald Hoyer 55891e
+        }
Harald Hoyer 55891e
         # Use two parallel streams to filter alternating modules.
Harald Hoyer 55891e
-        local merge side2
Harald Hoyer 55891e
-        ( ( local _f1 _f2
Harald Hoyer 55891e
-            while  read _f1; do   echo "$_f1"
Harald Hoyer 55891e
-                if read _f2; then echo "$_f2" 1>&${side2}; fi
Harald Hoyer 55891e
-            done \
Harald Hoyer 55891e
-            | nmf1     1>&${merge}    ) {side2}>&1 \
Harald Hoyer 55891e
-            | nmf1  )      {merge}>&1
Harald Hoyer 55891e
+        eval "( ( rotor ) ${_side2}>&1 | nmf1 ) ${_merge}>&1"
Harald Hoyer 55891e
     }
Harald Hoyer 55891e
 
Harald Hoyer 55891e
     find_kernel_modules_by_path drivers/net | net_module_filter | instmods
Harald Hoyer 55891e
diff --git a/modules.d/90kernel-modules/module-setup.sh b/modules.d/90kernel-modules/module-setup.sh
Harald Hoyer 55891e
index 09bd87e..6e3a918 100755
Harald Hoyer 55891e
--- a/modules.d/90kernel-modules/module-setup.sh
Harald Hoyer 55891e
+++ b/modules.d/90kernel-modules/module-setup.sh
Harald Hoyer 55891e
@@ -11,6 +11,8 @@ installkernel() {
Harald Hoyer 55891e
         }
Harald Hoyer 55891e
         block_module_filter() {
Harald Hoyer 55891e
             local _blockfuncs='ahci_init_controller|ata_scsi_ioctl|scsi_add_host|blk_init_queue|register_mtd_blktrans|scsi_esp_register|register_virtio_device'
Harald Hoyer 55891e
+            # subfunctions inherit following FDs
Harald Hoyer 55891e
+            local _merge=8 _side2=9
Harald Hoyer 55891e
             function bmf1() {
Harald Hoyer 55891e
                 local _f
Harald Hoyer 55891e
                 while read _f; do case "$_f" in
Harald Hoyer 55891e
@@ -19,14 +21,17 @@ installkernel() {
Harald Hoyer 55891e
                     esac
Harald Hoyer 55891e
                 done
Harald Hoyer 55891e
             }
Harald Hoyer 55891e
+            function rotor() {
Harald Hoyer 55891e
+                local _f1 _f2
Harald Hoyer 55891e
+                while read _f1; do
Harald Hoyer 55891e
+                    echo "$_f1"
Harald Hoyer 55891e
+                    if read _f2; then
Harald Hoyer 55891e
+                        echo "$_f2" 1>&${_side2}
Harald Hoyer 55891e
+                    fi
Harald Hoyer 55891e
+                done | bmf1 1>&${_merge}
Harald Hoyer 55891e
+            }
Harald Hoyer 55891e
             # Use two parallel streams to filter alternating modules.
Harald Hoyer 55891e
-            local merge side2
Harald Hoyer 55891e
-            ( ( local _f1 _f2
Harald Hoyer 55891e
-                while  read _f1; do   echo "$_f1"
Harald Hoyer 55891e
-                    if read _f2; then echo "$_f2" 1>&${side2}; fi
Harald Hoyer 55891e
-                done \
Harald Hoyer 55891e
-                | bmf1     1>&${merge}    ) {side2}>&1 \
Harald Hoyer 55891e
-                | bmf1  )      {merge}>&1
Harald Hoyer 55891e
+            eval "( ( rotor ) ${_side2}>&1 | bmf1 ) ${_merge}>&1"
Harald Hoyer 55891e
         }
Harald Hoyer 55891e
         hostonly='' instmods sr_mod sd_mod scsi_dh scsi_dh_rdac scsi_dh_emc
Harald Hoyer 55891e
         hostonly='' instmods pcmcia firewire-ohci