Harald Hoyer 0840a3
From 5a66d51102bc3522d46c60d8bd8e5d6837420063 Mon Sep 17 00:00:00 2001
Harald Hoyer 0840a3
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 0840a3
Date: Thu, 9 Jul 2015 14:13:44 +0200
Harald Hoyer 0840a3
Subject: [PATCH] dracut.sh: remove push()
Harald Hoyer 0840a3
Harald Hoyer 0840a3
can be done with var+=(val)
Harald Hoyer 0840a3
---
Harald Hoyer 0840a3
 dracut.sh | 77 +++++++++++++++++++++++----------------------------------------
Harald Hoyer 0840a3
 1 file changed, 28 insertions(+), 49 deletions(-)
Harald Hoyer 0840a3
Harald Hoyer 0840a3
diff --git a/dracut.sh b/dracut.sh
Harald Hoyer 0840a3
index bf1886f..f7609fa 100755
Harald Hoyer 0840a3
--- a/dracut.sh
Harald Hoyer 0840a3
+++ b/dracut.sh
Harald Hoyer 0840a3
@@ -209,30 +209,13 @@ For example:
Harald Hoyer 0840a3
 EOF
Harald Hoyer 0840a3
 }
Harald Hoyer 0840a3
 
Harald Hoyer 0840a3
-# function push()
Harald Hoyer 0840a3
-# push values to a stack
Harald Hoyer 0840a3
-# $1 = stack variable
Harald Hoyer 0840a3
-# $2.. values
Harald Hoyer 0840a3
-# example:
Harald Hoyer 0840a3
-# push stack 1 2 "3 4"
Harald Hoyer 0840a3
-push() {
Harald Hoyer 0840a3
-    local _i
Harald Hoyer 0840a3
-    local __stack=$1; shift
Harald Hoyer 0840a3
-    for _i in "$@"; do
Harald Hoyer 0840a3
-        eval ${__stack}'[${#'${__stack}'[@]}]="$_i"'
Harald Hoyer 0840a3
-    done
Harald Hoyer 0840a3
-}
Harald Hoyer 0840a3
-
Harald Hoyer 0840a3
 # Fills up host_devs stack variable and makes sure there are no duplicates
Harald Hoyer 0840a3
 push_host_devs() {
Harald Hoyer 0840a3
     local _dev
Harald Hoyer 0840a3
-    for _dev in ${host_devs[@]}; do
Harald Hoyer 0840a3
-        [ "$_dev" = "$1" ] && return
Harald Hoyer 0840a3
-    done
Harald Hoyer 0840a3
-    push host_devs "$1"
Harald Hoyer 0840a3
+    [[ " ${host_devs[@]} " == *" $1 "* ]] && return
Harald Hoyer 0840a3
+    host_devs+=( "$1" )
Harald Hoyer 0840a3
 }
Harald Hoyer 0840a3
 
Harald Hoyer 0840a3
-
Harald Hoyer 0840a3
 # function pop()
Harald Hoyer 0840a3
 # pops the last value from a stack
Harald Hoyer 0840a3
 # assigns value to second argument variable
Harald Hoyer 0840a3
@@ -486,28 +469,25 @@ while :; do
Harald Hoyer 0840a3
         PARMS_TO_STORE+=" $1";
Harald Hoyer 0840a3
     fi
Harald Hoyer 0840a3
     case $1 in
Harald Hoyer 0840a3
-        --kver)        kernel="$2";                    PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
-        -a|--add)      push add_dracutmodules_l  "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
-        --force-add)   push force_add_dracutmodules_l  "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
-        --add-drivers) push add_drivers_l        "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
-        --force-drivers) push force_drivers_l    "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
-        --omit-drivers) push omit_drivers_l      "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
-        -m|--modules)  push dracutmodules_l      "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
-        -o|--omit)     push omit_dracutmodules_l "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
-        -d|--drivers)  push drivers_l            "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
-        --filesystems) push filesystems_l        "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
-        -I|--install)  push install_items_l      "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
-        --install-optional)
Harald Hoyer 0840a3
-                       push install_optional_items_l \
Harald Hoyer 0840a3
-                                                 "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
-        --fwdir)       push fw_dir_l             "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
-        --libdirs)     push libdirs_l            "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
-        --fscks)       push fscks_l              "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
-        --add-fstab)   push add_fstab_l          "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
-        --mount)       push fstab_lines          "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
-        --add-device|--device)
Harald Hoyer 0840a3
-                       push add_device_l         "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
-        --kernel-cmdline) push kernel_cmdline_l  "$2"; PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        --kver)        kernel="$2";                           PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        -a|--add)      add_dracutmodules_l+=("$2");           PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        --force-add)   force_add_dracutmodules_l+=("$2");     PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        --add-drivers) add_drivers_l+=("$2");                 PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        --force-drivers) force_drivers_l+=("$2");             PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        --omit-drivers) omit_drivers_l+=("$2");               PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        -m|--modules)  dracutmodules_l+=("$2");               PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        -o|--omit)     omit_dracutmodules_l+=("$2");          PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        -d|--drivers)  drivers_l+=("$2");                     PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        --filesystems) filesystems_l+=("$2");                 PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        -I|--install)  install_items_l+=("$2");               PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        --install-optional) install_optional_items_l+=("$2"); PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        --fwdir)       fw_dir_l+=("$2");                      PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        --libdirs)     libdirs_l+=("$2");                     PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        --fscks)       fscks_l+=("$2");                       PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        --add-fstab)   add_fstab_l+=("$2");                   PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        --mount)       fstab_lines+=("$2");                   PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        --add-device|--device) add_device_l+=("$2");          PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
+        --kernel-cmdline) kernel_cmdline_l+=("$2");           PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
         --nofscks)     nofscks_l="yes";;
Harald Hoyer 0840a3
         --ro-mnt)      ro_mnt_l="yes";;
Harald Hoyer 0840a3
         -k|--kmoddir)  drivers_dir_l="$2";             PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
@@ -566,7 +546,7 @@ while :; do
Harald Hoyer 0840a3
                        persistent_policy_l="$2";       PARMS_TO_STORE+=" '$2'"; shift;;
Harald Hoyer 0840a3
         --fstab)       use_fstab_l="yes" ;;
Harald Hoyer 0840a3
         -h|--help)     long_usage; exit 1 ;;
Harald Hoyer 0840a3
-        -i|--include)  push include_src "$2";          PARMS_TO_STORE+=" '$2'";
Harald Hoyer 0840a3
+        -i|--include)  include_src+=("$2");          PARMS_TO_STORE+=" '$2'";
Harald Hoyer 0840a3
                        shift;;
Harald Hoyer 0840a3
         --bzip2)       compress_l="bzip2";;
Harald Hoyer 0840a3
         --lzma)        compress_l="lzma";;
Harald Hoyer 0840a3
@@ -602,8 +582,8 @@ done
Harald Hoyer 0840a3
 
Harald Hoyer 0840a3
 while (($# > 0)); do
Harald Hoyer 0840a3
     if [ "${1%%=*}" == "++include" ]; then
Harald Hoyer 0840a3
-        push include_src "$2"
Harald Hoyer 0840a3
-        push include_target "$3"
Harald Hoyer 0840a3
+        include_src+=("$2")
Harald Hoyer 0840a3
+        include_target+=("$3")
Harald Hoyer 0840a3
         PARMS_TO_STORE+=" --include '$2' '$3'"
Harald Hoyer 0840a3
         shift 2
Harald Hoyer 0840a3
     fi
Harald Hoyer 0840a3
@@ -746,7 +726,7 @@ fi
Harald Hoyer 0840a3
 
Harald Hoyer 0840a3
 if (( ${#fstab_lines_l[@]} )); then
Harald Hoyer 0840a3
     while pop fstab_lines_l val; do
Harald Hoyer 0840a3
-        push fstab_lines $val
Harald Hoyer 0840a3
+        fstab_lines+=($val)
Harald Hoyer 0840a3
     done
Harald Hoyer 0840a3
 fi
Harald Hoyer 0840a3
 
Harald Hoyer 0840a3
@@ -1199,11 +1179,11 @@ if [[ $hostonly ]]; then
Harald Hoyer 0840a3
         _bdev=$(readlink -f "/dev/block/$_dev")
Harald Hoyer 0840a3
         [[ -b $_bdev ]] && _dev=$_bdev
Harald Hoyer 0840a3
         push_host_devs $_dev
Harald Hoyer 0840a3
-        [[ "$mp" == "/" ]] && push root_devs "$_dev"
Harald Hoyer 0840a3
+        [[ "$mp" == "/" ]] && root_devs+=("$_dev")
Harald Hoyer 0840a3
         push_host_devs "$_dev"
Harald Hoyer 0840a3
         if [[ $(find_mp_fstype "$mp") == btrfs ]]; then
Harald Hoyer 0840a3
             for i in $(btrfs_devs "$mp"); do
Harald Hoyer 0840a3
-                [[ "$mp" == "/" ]] && push root_devs "$i"
Harald Hoyer 0840a3
+                [[ "$mp" == "/" ]] && root_devs+=("$i")
Harald Hoyer 0840a3
                 push_host_devs "$i"
Harald Hoyer 0840a3
             done
Harald Hoyer 0840a3
         fi
Harald Hoyer 0840a3
@@ -1237,7 +1217,7 @@ if [[ $hostonly ]]; then
Harald Hoyer 0840a3
 
Harald Hoyer 0840a3
                 _dev="$(readlink -f "$dev")"
Harald Hoyer 0840a3
                 push_host_devs "$_dev"
Harald Hoyer 0840a3
-                push swap_devs "$_dev"
Harald Hoyer 0840a3
+                swap_devs+=("$_dev")
Harald Hoyer 0840a3
                 break
Harald Hoyer 0840a3
             done < /etc/fstab
Harald Hoyer 0840a3
         done < /proc/swaps
Harald Hoyer 0840a3
@@ -1262,7 +1242,6 @@ if [[ $hostonly ]]; then
Harald Hoyer 0840a3
         done < /etc/fstab
Harald Hoyer 0840a3
     fi
Harald Hoyer 0840a3
 
Harald Hoyer 0840a3
-
Harald Hoyer 0840a3
     # record all host modaliases
Harald Hoyer 0840a3
     declare -A host_modalias
Harald Hoyer 0840a3
     find  /sys/devices/ -name uevent -print > "$initdir/.modalias"