]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
bash3 compat patch
authorMichal Soltys <soltys@ziu.info>
Mon, 10 Oct 2011 21:58:04 +0000 (23:58 +0200)
committerHarald Hoyer <harald@redhat.com>
Tue, 11 Oct 2011 07:37:01 +0000 (09:37 +0200)
This patch replaces:

- {var}>... redirections with functionally identical eval construct +
  explicit FDs
- ^^ and ,, case modifiers with temporary shopt

This allows us to lower minimum required bash version
to at least 3.1 (with current code).

Signed-off-by: Michal Soltys <soltys@ziu.info>
dracut-functions
modules.d/10i18n/module-setup.sh
modules.d/40network/module-setup.sh
modules.d/90kernel-modules/module-setup.sh

index ce593c935d37e16cde506978e4d3bd4361f21fcb..1ef5269d7f68a1a7cadd2dc63e7702780c83d4bd 100755 (executable)
@@ -821,10 +821,11 @@ install_kmod_with_fw() {
 #      It will be passed the full path to the found kernel module
 # $2 = module to get dependencies for
 # rest of args = arguments to modprobe
+# _fderr specifies FD passed from surrounding scope
 for_each_kmod_dep() {
     local _func=$1 _kmod=$2 _cmd _modpath _options _found=0
     shift 2
-    modprobe "$@" --ignore-install --show-depends $_kmod 2>&$modprobe_stderr | (
+    modprobe "$@" --ignore-install --show-depends $_kmod 2>&${_fderr} | (
         while read _cmd _modpath _options; do
             [[ $_cmd = insmod ]] || continue
             $_func ${_modpath} || exit $?
@@ -885,6 +886,8 @@ find_kernel_modules () {
 # install kernel modules along with all their dependencies.
 instmods() {
     [[ $no_kernel = yes ]] && return
+    # called [sub]functions inherit _fderr
+    local _fderr=9
 
     function inst1mod() {
         local _mod="$1"
@@ -949,9 +952,9 @@ instmods() {
         return $_ret
     }
 
-    # Capture all stderr from modprobe onto a new fd $modprobe_stderr,
-    # and pipe it into egrep.  See REDIRECTION in bash manpage.
-    ( instmods_1 "$@" ) {modprobe_stderr}>&1 \
+    # Capture all stderr from modprobe to _fderr. We could use {var}>...
+    # redirections, but that would make dracut require bash4 at least.
+    eval "( instmods_1 \"\$@\" ) ${_fderr}>&1" \
     | egrep -v 'FATAL: Module .* not found.' | derror
     return $?
 }
index 5c091004829f2bfccbccad8b91332c82728daec1..62486076b247113d4d17812fae743930e38e0873 100755 (executable)
@@ -150,22 +150,24 @@ install() {
             inst_simple ${kbddir}/unimaps/${FONT_UNIMAP}.uni
         fi
 
+        shopt -q -s nocasematch
         if [[ ${UNICODE} ]]
         then
-            if [[ ${UNICODE^^} = YES || ${UNICODE} = 1 ]]
+            if [[ ${UNICODE} = YES || ${UNICODE} = 1 ]]
             then
                 UNICODE=1
-            elif [[ ${UNICODE^^} = NO || ${UNICODE} = 0 ]]
+            elif [[ ${UNICODE} = NO || ${UNICODE} = 0 ]]
             then
                 UNICODE=0
             else
                 UNICODE=''
             fi
         fi
-        if [[ ! ${UNICODE} && ${LANG^^} =~ .*\.UTF-?8 ]]
+        if [[ ! ${UNICODE} && ${LANG} =~ .*\.UTF-?8 ]]
         then
             UNICODE=1
         fi
+        shopt -q -u nocasematch
 
         mksubdirs ${initdir}${I18N_CONF}
         mksubdirs ${initdir}${VCONFIG_CONF}
index 03684f118e4c3c84e9bf631268036f3f918268df..eb7ef9bbd158533651d22f8352b58111ad0e7426 100755 (executable)
@@ -27,6 +27,8 @@ installkernel() {
     net_module_filter() {
         local _net_drivers='eth_type_trans|register_virtio_device'
         local _unwanted_drivers='/(wireless|isdn|uwb)/'
+        # subfunctions inherit following FDs
+        local _merge=8 _side2=9
         function nmf1() {
             local _fname _fcont
             while read _fname; do
@@ -40,14 +42,17 @@ installkernel() {
                 && echo "$_fname"
             done
         }
+        function rotor() {
+            local _f1 _f2
+            while read _f1; do
+                echo "$_f1"
+                if read _f2; then
+                    echo "$_f2" 1>&${_side2}
+                fi
+            done | nmf1 1>&${_merge}
+        }
         # Use two parallel streams to filter alternating modules.
-        local merge side2
-        ( ( local _f1 _f2
-            while  read _f1; do   echo "$_f1"
-                if read _f2; then echo "$_f2" 1>&${side2}; fi
-            done \
-            | nmf1     1>&${merge}    ) {side2}>&1 \
-            | nmf1  )      {merge}>&1
+        eval "( ( rotor ) ${_side2}>&1 | nmf1 ) ${_merge}>&1"
     }
 
     find_kernel_modules_by_path drivers/net | net_module_filter | instmods
index 09bd87ef247967592894f078b6b8ac717f1181e3..6e3a91801fbac8af9221f0e878106be5138eaab3 100755 (executable)
@@ -11,6 +11,8 @@ installkernel() {
         }
         block_module_filter() {
             local _blockfuncs='ahci_init_controller|ata_scsi_ioctl|scsi_add_host|blk_init_queue|register_mtd_blktrans|scsi_esp_register|register_virtio_device'
+            # subfunctions inherit following FDs
+            local _merge=8 _side2=9
             function bmf1() {
                 local _f
                 while read _f; do case "$_f" in
@@ -19,14 +21,17 @@ installkernel() {
                     esac
                 done
             }
+            function rotor() {
+                local _f1 _f2
+                while read _f1; do
+                    echo "$_f1"
+                    if read _f2; then
+                        echo "$_f2" 1>&${_side2}
+                    fi
+                done | bmf1 1>&${_merge}
+            }
             # Use two parallel streams to filter alternating modules.
-            local merge side2
-            ( ( local _f1 _f2
-                while  read _f1; do   echo "$_f1"
-                    if read _f2; then echo "$_f2" 1>&${side2}; fi
-                done \
-                | bmf1     1>&${merge}    ) {side2}>&1 \
-                | bmf1  )      {merge}>&1
+            eval "( ( rotor ) ${_side2}>&1 | bmf1 ) ${_merge}>&1"
         }
         hostonly='' instmods sr_mod sd_mod scsi_dh scsi_dh_rdac scsi_dh_emc
         hostonly='' instmods pcmcia firewire-ohci