SVN: geninitrd/trunk/geninitrd

glen glen at pld-linux.org
Thu Oct 25 10:15:56 CEST 2007


Author: glen
Date: Thu Oct 25 10:15:56 2007
New Revision: 8868

Modified:
   geninitrd/trunk/geninitrd
Log:
- cosmetics
- take modprobe -c as modules source by default (you can now use include statement there)

Modified: geninitrd/trunk/geninitrd
==============================================================================
--- geninitrd/trunk/geninitrd	(original)
+++ geninitrd/trunk/geninitrd	Thu Oct 25 10:15:56 2007
@@ -210,7 +210,7 @@
 	fi
 
 	first=
-	for f in $mods ; do
+	for f in $mods; do
 		if [ "$first" = "" ]; then
 			first=$f
 		else
@@ -236,7 +236,7 @@
 	# only need to add each module once
 	# quote /
 	local tmpFmPath=$(echo $fmPath | awk '{gsub(/\//,"\\/");print}')
-	if echo "$MODULES" | awk '/'"$tmpFmPath"'/ {exit 1}' ; then
+	if echo "$MODULES" | awk '/'"$tmpFmPath"'/ {exit 1}'; then
 		MODULES="$MODULES $fmPath"
 	fi
 }
@@ -295,6 +295,31 @@
 	done
 }
 
+# output modules.conf / modprobe.conf
+modprobe_conf() {
+	echo "$modprobe_conf_cache"
+}
+
+#
+# defaults to modprobe -c if not told otherwise, this means include statements
+# work from there.
+cache_modprobe_conf() {
+	if [ "$pack_version" -lt "002005" ]; then
+		modulefile=/etc/modules.conf
+		if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
+			modulefile=/etc/conf.modules
+		fi
+	fi
+
+	if [ -n "$modulefile" ]; then
+		debug "modprobe: using $modulefile"
+		modprobe_conf_cache=$(cat $modulefile)
+	else
+		debug "modprobe: using modprobe -c"
+		modprobe_conf_cache=$(modprobe -c)
+	fi
+}
+
 find_modules_md() {
 	local found raidlevel
 
@@ -339,7 +364,7 @@
 		die "raidtools are not longer supported. Please migrate to mdadm setup!"
 	fi
 
-	if is_yes "$have_md" ; then
+	if is_yes "$have_md"; then
 		case "$raidlevel" in
 		[01]|10)
 			findmodule "raid$raidlevel"
@@ -373,7 +398,7 @@
 	for n in $PRESCSIMODS; do
 		if [ "X$n" = "Xunknown" ]; then
 			if [ -f "$modulefile" ]; then
-				scsimodules="`awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
+				local scsimodules=$(modprobe_conf | awk '/scsi_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
 				for n in $scsimodules; do
 			# for now allow scsi modules to come from anywhere. There are some
 			# RAID controllers with drivers in block
@@ -404,14 +429,12 @@
 		local tryauto=1
 		for n in $PREIDEMODS; do
 			if [ "X$n" = "Xunknown" ]; then
-				if [ -f "$modulefile" ]; then
-					debug "Finding IDE modules using ide_hostadapter"
-					idemodules="`awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
-					for na in $idemodules; do
-						tryauto=0;
-						findmodule "$na"
-					done
-				fi
+				debug "Finding IDE modules using ide_hostadapter"
+				local mod idemodules=$(modprobe_conf | awk '/ide_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
+				for mod in $idemodules; do
+					tryauto=0;
+					findmodule "$mod"
+				done
 
 				if [ "$tryauto" -eq 1 ]; then
 					# If tryauto {{{
@@ -638,12 +661,12 @@
 		# fallback
 	fi
 
-	if is_yes "$(echo "$devpath" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')" ; then
+	if is_yes "$(echo "$devpath" | awk '/^\/dev\/(sd|scsi)/ { print "yes"; }')"; then
 		find_modules_scsi
 		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
@@ -666,10 +689,10 @@
 	if [[ "$devpath" == /dev/ataraid/* ]]; then
 		find_modules_ide
 		findmodule "ataraid"
-		ataraidmodules="`awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }' $modulefile`"
+		ataraidmodules=$(modprobe_conf | awk '/ataraid_hostadapter/ && ! /^[\t ]*#/ { print $3; }')
 		if [ -n "$ataraidmodules" ]; then
 			# FIXME: think about modules compiled in kernel
-			die "ataraid_hostadapter alias not defined in $modulefile! Please set it and run $PROGRAM again."
+			die "ataraid_hostadapter alias not defined in modprobe.conf! Please set it and run $PROGRAM again."
 		fi
 		for n in $ataraidmodules; do
 			findmodule "$n"
@@ -685,7 +708,7 @@
 			die "losetup is missing"
 		fi
 		key="^# $(echo $devpath | awk -F/ '{print($3);}' | tr '[a-z]' '[A-Z]'):"
-		if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`" ; then
+		if ! is_yes "`awk '/'$key'/ { print( "yes"); }' $fstab`"; then
 			die "The root filesystem is on a $devpath, but there is no magic entry in $fstab for this device. Consult the geninitrd man page for more information"
 		fi
 
@@ -797,7 +820,7 @@
 		NAME2=`basename "$mod" .gz`
 		MODULE2=$MODULE2/$NAME2
 		module="`echo $mod | awk -F/ '{ $0=$NF } /'$modext'.*$/ { gsub(/'$modext'.*/, NIL, $0); } { print $0; }'`"
-		options="`awk '{ if($1 == "options" && $2 == "'${module}'") { for(i=3;i<=NF;i++) printf("%s ",$i); }}' "$modulefile"`"
+		options=$(modprobe_conf | awk -vmodule="$module" '{ if ($1 == "options" && $2 == module) { for(i=3;i<=NF;i++) printf("%s ",$i); }}')
 
 		generic_module=$(echo "${module}" | awk ' { gsub("-", "_", $0) } { print $0; } ')
 		sleep_var="$(eval echo \$MODULE_${generic_module}_USLEEP)"
@@ -1020,7 +1043,7 @@
 	insmod="insmod"
 fi
 
-if is_yes "$USEINSMODSTATIC" ; then
+if is_yes "$USEINSMODSTATIC"; then
 	insmod="insmod.static"
 	INSMOD="/sbin/insmod.static"
 	if [ "$pack_version" -lt "002005" -a -f /sbin/insmod.static.modutils ]; then
@@ -1088,25 +1111,18 @@
 	echo >&2 "WARNING: /proc filesystem not mounted, may cause wrong results or failure."
 fi
 
-if [ "$pack_version" -lt "002005" ]; then
-	modulefile=/etc/modules.conf
-	if [ ! -f "$modulefile" -a -f /etc/conf.modules ]; then
-		modulefile=/etc/conf.modules
-	fi
-else
-	modulefile=/etc/modprobe.conf
-fi
+cache_modprobe_conf
 
 for n in $PREMODS; do
 	findmodule "$n"
 done
 
 # allow forcing loading SCSI and/or IDE modules
-if is_yes "$ADDSCSI" ; then
+if is_yes "$ADDSCSI"; then
 	find_modules_scsi
 fi
 
-if is_yes "$ADDIDE" ; then
+if is_yes "$ADDIDE"; then
 	find_modules_ide
 fi
 
@@ -1745,13 +1761,13 @@
 		mkcramfs "$MNTPOINT" "$IMAGE"
 		;;
 	initramfs)
-		(cd $MNTPOINT ; find . | cpio --quiet -H newc -o > "$IMAGE")
+		(cd $MNTPOINT; find . | cpio --quiet -H newc -o > "$IMAGE")
 		;;
 	*)
 		echo "Filesystem $INITRDFS not supported by $PROGRAM";
 esac
 
-if is_yes "$COMPRESS" ; then
+if is_yes "$COMPRESS"; then
 	gzip -9 < "$IMAGE" > "$target"
 else
 	cp -a "$IMAGE" "$target"


More information about the pld-cvs-commit mailing list