]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
dracut-functions: code formatting corrected
authorAmadeusz Żołnowski <aidecoe@aidecoe.name>
Fri, 25 Mar 2011 14:56:46 +0000 (15:56 +0100)
committerHarald Hoyer <harald@redhat.com>
Fri, 25 Mar 2011 15:21:08 +0000 (16:21 +0100)
dracut-functions

index bf2581e3facf2f9c629f29074ba59ecea2b4e21d..3b664af8291e815ca466f1114dec987585149431 100755 (executable)
@@ -70,7 +70,7 @@ vercmp() {
 }
 
 is_func() {
-    [[ $(type -t $1) = "function" ]] 
+    [[ $(type -t $1) = "function" ]]
 }
 
 # Function prints global variables in format name=value line by line.
@@ -119,25 +119,25 @@ get_fs_uuid() (
 # finds the major:minor of the block device backing the root filesystem.
 find_block_device() {
     local x mpt majmin dev fs misc maj min
-    if [[ $use_fstab != yes ]]; then    
+    if [[ $use_fstab != yes ]]; then
         while read x x majmin x mpt x x fs dev misc; do
             [[ $fs = nfs ]] && { echo $dev; return 0;}
             [[ $fs = nfs3 ]] && { echo $dev; return 0;}
             [[ $fs = nfs4 ]] && { echo $dev; return 0;}
             [[ $fs = btrfs ]] && {
-                ls -nLl "$dev" | { 
-                    read x x x x maj min x;
-                    maj=${maj//,/}
-                    echo $maj:$min
+                ls -nLl "$dev" | {
+                    read x x x x maj min x
+                    maj=${maj//,/}
+                    echo $maj:$min
                 } && return 0
             }
             if [[ $mpt = $1 ]] && [[ ${majmin#0:} = $majmin ]]; then
-                echo $majmin
+                echo $majmin
                 return 0 # we have a winner!
             fi
-        done < /proc/self/mountinfo       
+        done < /proc/self/mountinfo
     fi
-    # fall back to /etc/fstab    
+    # fall back to /etc/fstab
     while read dev mpt fs misc; do
         if [[ $mpt = $1 ]]; then
             [[ $fs = nfs ]] && { echo $dev; return 0;}
@@ -146,14 +146,15 @@ find_block_device() {
             [[ $dev != ${dev#UUID=} ]] && dev=/dev/disk/by-uuid/${dev#UUID=}
             [[ $dev != ${dev#LABEL=} ]] && dev=/dev/disk/by-label/${dev#LABEL=}
             [[ -b $dev ]] || return 1 # oops, not a block device.
-            ls -nLl "$dev" | { 
-                read x x x x maj min x;
-                maj=${maj//,/}
-                echo $maj:$min
+            ls -nLl "$dev" | {
+                read x x x x maj min x
+                maj=${maj//,/}
+                echo $maj:$min
             } && return 0
         fi
     done < /etc/fstab
-    return 1;
+
+    return 1
 }
 
 find_root_block_device() { find_block_device /; }
@@ -162,24 +163,24 @@ find_root_block_device() { find_block_device /; }
 # Stop when our helper function returns success
 # $1 = function to call on every found block device
 # $2 = block device in major:minor format
-check_block_and_slaves() {    
-    local x 
+check_block_and_slaves() {
+    local x
     [[ -b /dev/block/$2 ]] || return 1 # Not a block device? So sorry.
     "$1" $2 && return
     check_vol_slaves "$@" && return 0
     if [[ -f /sys/dev/block/$2/../dev ]]; then
-        check_block_and_slaves $1 $(cat "/sys/dev/block/$2/../dev") &&  return 0
+        check_block_and_slaves $1 $(cat "/sys/dev/block/$2/../dev") && return 0
     fi
     [[ -d /sys/dev/block/$2/slaves ]] || return 1
     for x in /sys/dev/block/$2/slaves/*/dev; do
         [[ -f $x ]] || continue
-        check_block_and_slaves $1 $(cat "$x") &&  return 0
+        check_block_and_slaves $1 $(cat "$x") && return 0
     done
     return 1
 }
 
 get_numeric_dev() {
-    ls -lH "$1" | { read a b c d maj min rest; printf "%d:%d" ${maj%%,} $min;}
+    ls -lH "$1" | { read a b c d maj min rest; printf "%d:%d" ${maj%%,} $min; }
 }
 
 # ugly workaround for the lvm design
@@ -189,17 +190,16 @@ get_numeric_dev() {
 # but you cannot create the logical volume without the volume group.
 # And the volume group might be bigger than the devices the LV needs.
 check_vol_slaves() {
-    for i in /dev/mapper/*; do 
+    for i in /dev/mapper/*; do
         lv=$(get_numeric_dev $i)
         if [[ $lv = $2 ]]; then
             vg=$(lvm lvs --noheadings -o vg_name $i 2>/dev/null)
             # strip space
             vg=$(echo $vg)
             if [[ $vg ]]; then
-                for pv in $(lvm vgs --noheadings -o pv_name "$vg" 2>/dev/null); \
-                    do
-                    check_block_and_slaves $1 $(get_numeric_dev $pv) \
-                        &&  return 0
+                for pv in $(lvm vgs --noheadings -o pv_name "$vg" 2>/dev/null)
+                do
+                    check_block_and_slaves $1 $(get_numeric_dev $pv) && return 0
                 done
             fi
         fi
@@ -228,7 +228,7 @@ inst_dir() {
             local target=$(readlink "$file")
             ln -sfn "$target" "${initdir}$file" || return 1
             # resolve relative path and recursively install destination
-            [[ $target == ${target#/} ]] && target=$(dirname "$file")/$target
+            [[ $target == ${target#/} ]] && target="$(dirname "$file")/$target"
             inst_dir "$target"
         else
             # create directory
@@ -242,7 +242,7 @@ inst_dir() {
 # Location of the image dir is assumed to be $initdir
 # We never overwrite the target if it exists.
 inst_simple() {
-    local src target 
+    local src target
     [[ -f $1 ]] || return 1
     src=$1 target="${2:-$1}"
     if ! [[ -d ${initdir}$target ]]; then
@@ -250,10 +250,10 @@ inst_simple() {
         inst_dir "${target%/*}"
     fi
     # install checksum files also
-    if [[ -e  "${src%/*}/.${src##*/}.hmac" ]]; then 
-       inst "${src%/*}/.${src##*/}.hmac" "${target%/*}/.${target##*/}.hmac"
+    if [[ -e "${src%/*}/.${src##*/}.hmac" ]]; then
+        inst "${src%/*}/.${src##*/}.hmac" "${target%/*}/.${target##*/}.hmac"
     fi
-    dinfo "Installing $src" 
+    dinfo "Installing $src"
     cp -pfL "$src" "${initdir}$target"
 }
 
@@ -279,7 +279,7 @@ rev_lib_symlinks() {
         [[ -L ${fn} && $(readlink -f "${fn}") == ${orig} ]] && links+=" ${fn}"
     done
 
-    echo ${links}
+    echo "${links}"
 }
 
 # Same as above, but specialized to handle dynamic libraries.
@@ -289,15 +289,15 @@ inst_library() {
     local src=$1 dest=${2:-$1} lib reallib symlink
     [[ -e $initdir$dest ]] && return 0
     if [[ -L $src ]]; then
-       # install checksum files also
-        if [[ -e  "${src%/*}/.${src##*/}.hmac" ]]; then 
+        # install checksum files also
+        if [[ -e "${src%/*}/.${src##*/}.hmac" ]]; then
             inst "${src%/*}/.${src##*/}.hmac" "${dest%/*}/.${dest##*/}.hmac"
         fi
-       reallib=$(readlink -f "$src")
-       lib=${src##*/}
-       inst_simple "$reallib" "$reallib"
-       inst_dir "${dest%/*}"
-       (cd "${initdir}${dest%/*}" && ln -s "$reallib" "$lib")
+        reallib=$(readlink -f "$src")
+        lib=${src##*/}
+        inst_simple "$reallib" "$reallib"
+        inst_dir "${dest%/*}"
+        (cd "${initdir}${dest%/*}" && ln -s "$reallib" "$lib")
     else
         inst_simple "$src" "$dest"
     fi
@@ -364,7 +364,7 @@ inst_binary() {
             IF_dynamic=yes
             continue
             fi
-            inst_library "$FILE" 
+            inst_library "$FILE"
     done
     inst_simple "$bin" "$target"
 }
@@ -404,7 +404,7 @@ find_rule() {
 
 # udev rules always get installed in the same place, so
 # create a function to install them to make life simpler.
-inst_rules() { 
+inst_rules() {
     local target=/etc/udev/rules.d rule found
 
     inst_dir "/lib/udev/rules.d"
@@ -433,7 +433,7 @@ inst() {
         1) ;;
         2) [[ ! $initdir && -d $2 ]] && export initdir=$2
             [[ $initdir = $2 ]] && set $1;;
-        3) [[ -z $initdir ]] && export initdir=$2 
+        3) [[ -z $initdir ]] && export initdir=$2
             set $1 $3;;
         *) derror "inst only takes 1 or 2 or 3 arguments"
             exit 1;;
@@ -459,14 +459,14 @@ inst_hook() {
         derror "Aborting initrd creation."
         exit 1
     elif ! strstr "$hookdirs" "$1"; then
-        derror "No such hook type $1. Aborting initrd creation." 
+        derror "No such hook type $1. Aborting initrd creation."
         exit 1
     fi
     inst_simple "$3" "/lib/dracut/hooks/${1}/${2}${3##*/}"
 }
 
 dracut_install() {
-    if [[ $1 = '-o' ]]; then 
+    if [[ $1 = '-o' ]]; then
         local optional=yes
         shift
     fi
@@ -671,9 +671,10 @@ install_kmod_with_fw() {
     local modname=${1##*/} fwdir found
     modname=${modname%.ko*}
     # no need to go further if the module is already installed
-    [[ -e  "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] && return 0
-    inst_simple "$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" || \
-       return $? 
+    [[ -e "${initdir}/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" ]] \
+        && return 0
+    inst_simple "$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}" \
+        || return $?
     for fw in $(modinfo -k $kernel -F firmware $1 2>/dev/null); do
         found=''
         for fwdir in $fw_dir; do
@@ -691,20 +692,23 @@ install_kmod_with_fw() {
 
 # Do something with all the dependencies of a kernel module.
 # Note that kernel modules depend on themselves using the technique we use
-# $1 = function to call for each dependency we find 
-#      It will be passed the full path to the found kernel module 
+# $1 = function to call for each dependency we find
+#      It will be passed the full path to the found kernel module
 # $2 = module to get dependencies for
 # rest of args = arguments to modprobe
 for_each_kmod_dep() {
-    local func=$1 kmod=$2 cmd modpapth options 
+    local func=$1 kmod=$2 cmd modpapth options
     shift 2
-    modprobe "$@" --ignore-install --show-depends $kmod 2>/dev/null | ( \
-        local found=0;
-       while read cmd modpath options; do
-           [[ $cmd = insmod ]] || continue
-           $func ${modpath} || exit $?
+    modprobe "$@" --ignore-install --show-depends $kmod 2>/dev/null | (
+        local found=0
+        while read cmd modpath options; do
+            [[ $cmd = insmod ]] || continue
+            $func ${modpath} || exit $?
             found=1
-        done; [[ $found -eq 0 ]] && exit 1; exit 0;)
+        done
+        [[ $found -eq 0 ]] && exit 1
+        exit 0
+    )
     return $?
 }
 
@@ -718,16 +722,20 @@ for_each_kmod_dep() {
 # This function returns the full filenames of modules that match $1
 filter_kernel_modules () (
     if ! [[ $hostonly ]]; then
-        filtercmd='find "$srcmods/kernel/drivers" "$srcmods/extra" "$srcmods/weak-updates" -name "*.ko" -o -name "*.ko.gz" 2>/dev/null'
+        filtercmd='find "$srcmods/kernel/drivers" "$srcmods/extra"'
+        filtercmd+=' "$srcmods/weak-updates" -name "*.ko" -o -name "*.ko.gz"'
+        filtercmd+=' 2>/dev/null'
     else
-        filtercmd='cut -d " " -f 1 </proc/modules|xargs modinfo -F filename -k $kernel 2>/dev/null'
+        filtercmd='cut -d " " -f 1 </proc/modules|xargs modinfo -F filename '
+        filtercmd+='-k $kernel 2>/dev/null'
     fi
     for modname in $(eval $filtercmd); do
         case $modname in
             *.ko) "$1" "$modname" && echo "$modname";;
             *.ko.gz) gzip -dc "$modname" > $initdir/$$.ko
                 $1 $initdir/$$.ko && echo "$modname"
-                rm -f $initdir/$$.ko;;
+                rm -f $initdir/$$.ko
+                ;;
         esac
     done
 )
@@ -740,18 +748,19 @@ instmods() {
     while (($# > 0)); do
         mod=${1%.ko*}
         case $mod in
-            =*) 
+            =*)
                 # This introduces 2 incompatible meanings for =* arguments
                 # to instmods.  We need to decide which one to keep.
-                if [[ $mod = =ata && -f $srcmods/modules.block ]] ; then 
-                    instmods $mpargs $(egrep 'ata|ahci' "${srcmods}/modules.block")
+                if [[ $mod = =ata && -f $srcmods/modules.block ]]; then
+                    instmods $mpargs \
+                        $(egrep 'ata|ahci' "${srcmods}/modules.block")
                 elif [ -f $srcmods/modules.${mod#=} ]; then
                     instmods $mpargs $(cat ${srcmods}/modules.${mod#=} )
                 else
                     instmods $mpargs $(find "$srcmods" -path "*/${mod#=}/*")
                 fi
                 ;;
-            --*) 
+            --*)
                 mod=${mod##*/}
                 mpargs+=" $mod";;
             i2o_scsi) shift; continue;; # Do not load this diagnostic-only module
@@ -761,25 +770,25 @@ instmods() {
                 [[ -f $initdir/$1 ]] && { shift; continue; }
                 # If we are building a host-specific initramfs and this
                 # module is not already loaded, move on to the next one.
-                [[ $hostonly ]] && ! grep -qe "\<${mod//-/_}\>" /proc/modules && \
-                    ! echo $add_drivers | grep -qe "\<${mod}\>" &&  {
-                    shift; continue; 
-                }
+                [[ $hostonly ]] && ! grep -qe "\<${mod//-/_}\>" /proc/modules \
+                    && ! echo $add_drivers | grep -qe "\<${mod}\>" && {
+                        shift; continue
+                    }
 
                 # We use '-d' option in modprobe only if modules prefix path
                 # differs from default '/'.  This allows us to use Dracut with
                 # old version of modprobe which doesn't have '-d' option.
                 moddirname=${srcmods%%/lib/modules/*}
                 [[ -n ${moddirname} ]] && moddirname="-d ${moddirname}/"
-                
+
                 # ok, load the module, all its dependencies, and any firmware
                 # it may require
                 for_each_kmod_dep install_kmod_with_fw $mod \
                     --set-version $kernel ${moddirname}
                 ret=$((ret+$?))
                 ;;
-        esac      
+        esac
         shift
     done
     return $ret
-} 
+}