[readonly/geninitrd: 468/1068] - optimize, cosmetics

draenog draenog at pld-linux.org
Sat Nov 2 19:51:43 CET 2013


commit c3667d07d0614126cbd50adde4c48ed5d1a7a3ee
Author: Elan Ruusamäe <glen at pld-linux.org>
Date:   Thu Oct 25 07:46:11 2007 +0000

    - optimize, cosmetics
    
    svn-id: @8867

 geninitrd | 133 ++++++++++++++++++++++++++++++++------------------------------
 1 file changed, 68 insertions(+), 65 deletions(-)
---
diff --git a/geninitrd b/geninitrd
index 1ade92f..ac52f61 100755
--- a/geninitrd
+++ b/geninitrd
@@ -7,7 +7,7 @@
 # based on mkinitrd from RedHat Linux
 #
 # TODO:
-# - make udev start before insomds
+# - make udev start before insmods
 # - make proper use of USE_UDEV - don't copy fules if USE_UDEV is off no!
 # - sanitize - one mounting of /proc and /sys at the begining and one umount at the end!
 #
@@ -19,14 +19,12 @@ PROGRAM=${0##*/}
 . /etc/rc.d/init.d/functions
 . /etc/geninitrd/functions
 
-COMPRESS="yes"
-# INITRDFS is set later (catch obsoleted FS option)
-#INITRDFS="rom"
-USERAIDSTART="yes"
-USEMDADMSTATIC="no"
-USEINSMODSTATIC="no"
-USE_SUSPEND="yes"
-USE_TUXONICE="yes"
+COMPRESS=yes
+USERAIDSTART=yes
+USEMDADMSTATIC=no
+USEINSMODSTATIC=no
+USE_SUSPEND=yes
+USE_TUXONICE=yes
 # it should be safe to remove scsi_mod from here, but I'm not sure...
 PRESCSIMODS="-scsi_mod unknown -sd_mod"
 PREIDEMODS="-ide-core unknown -ide-detect -ide-disk"
@@ -37,10 +35,9 @@ force=""
 verbose=""
 MODULES=""
 img_vers=""
-modulefile=""
-fstab="/etc/fstab"
-insmod="insmod"
-modext=".o"
+fstab=/etc/fstab
+insmod=insmod
+modext=.o
 rootdev_nr=0
 # device node for rootfs from fstab
 rootdev=""
@@ -73,16 +70,16 @@ have_dmraid=no
 have_multipath=no
 
 if [ -f /etc/udev/udev.conf -a -x /sbin/initrd-udevd ]; then
-	USE_UDEV="yes"
+	USE_UDEV=yes
 	. /etc/udev/udev.conf
 fi
 
 if [ -x /sbin/dmraid-initrd ]; then
-	USE_DMRAID="yes"
+	USE_DMRAID=yes
 fi
 
 if [ -x /sbin/multipath ]; then
-	USE_MULTIPATH="yes"
+	USE_MULTIPATH=yes
 fi
 
 usage () {
@@ -225,8 +222,8 @@ BEGIN { here = 0 }
 }
 
 addmodule() {
-	fmPath=$1
-	skiperrors=$2
+	local fmPath=$1
+	local skiperrors=$2
 
 	if [ ! -f "/lib/modules/$kernel/$fmPath" ]; then
 		if [ -n "$skiperrors" ]; then
@@ -238,15 +235,15 @@ addmodule() {
 
 	# only need to add each module once
 	# quote /
-	tmpFmPath=$(echo $fmPath | awk '{gsub(/\//,"\\/");print}')
+	local tmpFmPath=$(echo $fmPath | awk '{gsub(/\//,"\\/");print}')
 	if echo "$MODULES" | awk '/'"$tmpFmPath"'/ {exit 1}' ; then
 		MODULES="$MODULES $fmPath"
 	fi
 }
 
 findmodule() {
-	skiperrors=""
-	modName=$1
+	local skiperrors=""
+	local modName=$1
 
 	if [ ${modName#-} != ${modName} ]; then
 		skiperrors=1
@@ -263,6 +260,7 @@ findmodule() {
 		findmodule socal
 	fi
 
+	local mod allModulesToFind
 	if [ -n "$skiperrors" ]; then
 		allModulesToFind=$(find_depmod silent $modName)
 	else
@@ -371,6 +369,7 @@ find_modules_md() {
 }
 
 find_modules_scsi() {
+	local n
 	for n in $PRESCSIMODS; do
 		if [ "X$n" = "Xunknown" ]; then
 			if [ -f "$modulefile" ]; then
@@ -389,18 +388,20 @@ find_modules_scsi() {
 }
 
 find_modules_ide() {
-	local rootblkdev
-
+	local devpath=$1
+	# remove partition, if any
+	local disk=${devpath%[0-9]*}
 	# set blockdev for rootfs (hda, sdc, ...)
-	rootblkdev="$(echo "$1" | awk ' { gsub(/\/dev\//,NUL); gsub(/[0-9].*/, NUL); print $0 } ')"
+	local rootblkdev=${disk#/dev/}
 
+	local n
 	if [ "$pack_version_long" -lt "002004021" ]; then
 		debug "Finding IDE modules for kernels <= 2.4.20"
 		for n in $PREIDEMODSOLD; do
 			findmodule "$n"
 		done
 	else
-		tryauto=1
+		local tryauto=1
 		for n in $PREIDEMODS; do
 			if [ "X$n" = "Xunknown" ]; then
 				if [ -f "$modulefile" ]; then
@@ -642,7 +643,7 @@ find_modules_for_device() {
 		return
 	fi
 
-	if is_yes "`echo "$devpath" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }'`" ; then
+	if is_yes "$(echo "$devpath" | awk '/^\/dev\/(hd|ide)/ { print "yes"; }')" ; then
 		find_modules_ide "$devpath"
 		return
 	fi
@@ -737,9 +738,9 @@ find_modules_for_device() {
 }
 
 firmware_install_module_pre() {
-	module="$1"
-	linuxrc="$2"
-	firmware_files="$3"
+	local module="$1"
+	local linuxrc="$2"
+	local firmware_files="$3"
 
 	debug "Adding Firmwares ($firmware_files) to initrd for module $module"
 	inst_d /proc
@@ -767,15 +768,16 @@ EOF
 }
 
 firmware_install_module_post() {
-	module="$1"
-	linuxrc="$2"
-	firmware_files="$3"
+	local module="$1"
+	local linuxrc="$2"
+	local firmware_files="$3"
 	echo "umount /sys" >> "$linuxrc"
 	echo "umount /proc" >> "$linuxrc"
 }
 
 modules_install() {
-	modules="$1"
+	local modules="$1"
+	local mod
 
 	for mod in $modules; do
 		MODULEDIR=$(dirname "$mod")
@@ -786,8 +788,9 @@ modules_install() {
 }
 
 modules_add_linuxrc() {
-	modules="$1"
-	linuxrc="$2"
+	local modules="$1"
+	local linuxrc="$2"
+	local mod
 
 	for mod in $modules; do
 		MODULE2="`dirname "$mod"`"
@@ -852,76 +855,76 @@ fi
 while [ $# -gt 0 ]; do
 	case $1 in
 	--fstab=*)
-		fstab="`echo $1 | awk -F= '{print $2;}'`"
+		fstab=${1#--fstab=}
 		;;
 	--fstab)
-		fstab="$2"
+		fstab=$2
 		shift
 		;;
 	--modules-conf=*)
-		modulefile="`echo $1 | awk -F= '{print $2;}'`"
+		modulefile=${1#--modules-conf=}
 		;;
 	--modules-conf)
-		modulefile="$2"
+		modulefile=$2
 		shift
 		;;
 	--use-raidstart|--with-raidstart)
-		USERAIDSTART="yes"
+		USERAIDSTART=yes
 		;;
 	--without-raidstart)
-		USERAIDSTART="no"
+		USERAIDSTART=no
 		;;
 	--use-insmod-static|--with-insmod-static)
-		USEINSMODSTATIC="yes"
+		USEINSMODSTATIC=yes
 		;;
 	--without-insmod-static)
-		USEINSMODSTATIC="no"
+		USEINSMODSTATIC=no
 		;;
 	--with-bootsplash)
-		BOOT_SPLASH="yes"
+		BOOT_SPLASH=yes
 		;;
 	--without-bootsplash)
-		BOOT_SPLASH="no"
+		BOOT_SPLASH=no
 		;;
 	--with-fbsplash)
-		FB_SPLASH="yes"
+		FB_SPLASH=yes
 		;;
 	--without-fbsplash)
-		FB_SPLASH="no"
+		FB_SPLASH=no
 		;;
 	--with-suspend)
-		USE_SUSPEND="yes"
+		USE_SUSPEND=yes
 		;;
 	--without-suspend)
-		USE_SUSPEND="no"
+		USE_SUSPEND=no
 		;;
 	--with-suspend2 | --with-tuxonice)
-		USE_TUXONICE="yes"
+		USE_TUXONICE=yes
 		;;
 	--without-suspend2 | --without-tuxonice)
-		USE_TUXONICE="no"
+		USE_TUXONICE=no
 		;;
 	--lvmtoolsversion=|--lvmversion=)
 		LVMTOOLSVERSION="`echo $1 | awk -F= '{print $2;}'`"
 		;;
 	--lvmtoolsversion|--lvmversion)
-		LVMTOOLSVERSION="$2"
+		LVMTOOLSVERSION=$2
 		shift
 		;;
 	--without-udev)
-		USE_UDEV=
+		USE_UDEV=no
 		;;
 	--with-udev)
-		USE_UDEV="yes"
+		USE_UDEV=yes
 		;;
 	--without-dmraid)
-		USE_DMRAID=
+		USE_DMRAID=no
 		;;
 	--without-multipath)
-		USE_MULTPATH=
+		USE_MULTPATH=no
 		;;
 	--with=*)
-		BASICMODULES="$BASICMODULES `echo $1 | awk -F= '{print $2;}'`"
+		BASICMODULES="$BASICMODULES ${1#--with=}"
 		;;
 	--with)
 		BASICMODULES="$BASICMODULES $2"
@@ -935,7 +938,7 @@ while [ $# -gt 0 ]; do
 		verbose=-v
 		;;
 	--nocompress)
-		COMPRESS="no"
+		COMPRESS=no
 		;;
 	--ifneeded)
 		ifneeded=1
@@ -944,7 +947,7 @@ while [ $# -gt 0 ]; do
 		force=1
 		;;
 	--preload=*)
-		PREMODS="$PREMODS `echo $1 | awk -F= '{print $2;}'`"
+		PREMODS="$PREMODS ${1#--preload=}"
 		;;
 	--preload)
 		PREMODS="$PREMODS $2"
@@ -952,18 +955,18 @@ while [ $# -gt 0 ]; do
 		;;
 	--fs=*)
 		echo >&2 "Warning: --fs option is obsoleted. Use --initrdfs instead"
-		INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
+		INITRDFS=${1#--fs=}
 		;;
 	--fs)
 		echo >&2 "Warning: --fs option is obsoleted. Use --initrdfs instead"
-		INITRDFS="$2"
+		INITRDFS=$2
 		shift
 		;;
 	--initrdfs=*)
-		INITRDFS="`echo $1 | awk -F= '{print $2;}'`"
+		INITRDFS=${1#--initrdfs=}
 		;;
 	--initrdfs)
-		INITRDFS="$2"
+		INITRDFS=$2
 		shift
 		;;
 	--image-version)
@@ -1008,8 +1011,8 @@ if [ "x" = "x$INITRDFS" ]; then
 fi
 
 if [ "$pack_version" -lt "002006" ]; then
-	USE_UDEV=
-	USE_DMRAID=
+	USE_UDEV=no
+	USE_DMRAID=no
 fi
 
 if [ "$pack_version" -ge "002005" ]; then
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/readonly/geninitrd.git/commitdiff/147754ca159d40ca5eb541074dc043d8cbd92090



More information about the pld-cvs-commit mailing list