[readonly/geninitrd: 450/1068] - add inst_d() utility function to make dirs

draenog draenog at pld-linux.org
Sat Nov 2 19:50:12 CET 2013


commit 034fdd5de7e6c55da4c41acf2223faedf771ddc0
Author: Elan Ruusamäe <glen at pld-linux.org>
Date:   Tue Oct 23 15:16:51 2007 +0000

    - add inst_d() utility function to make dirs
    
    svn-id: @8841

 geninitrd | 61 ++++++++++++++++++++++++++++++-------------------------------
 1 file changed, 30 insertions(+), 31 deletions(-)
---
diff --git a/geninitrd b/geninitrd
index 510f7f5..53ba6e6 100755
--- a/geninitrd
+++ b/geninitrd
@@ -264,6 +264,9 @@ findmodule() {
 	done
 }
 
+# install a file to temporary mount image.
+# it will operate recursively (copying directories)
+# and will symlink destinations if source is symlink.
 inst() {
 	if [ "$#" != "2" ];then
 		die 'Usage: inst <file> $MNTIMAGE<destination>'
@@ -272,6 +275,16 @@ inst() {
 	cp -HR "$1" "$MNTIMAGE$2"
 }
 
+inst_dir() {
+	if [ "$#" = "0" ];then
+		die 'Usage: inst_dir $MNTIMAGE<destination> $MNTIMAGE<destination>'
+	fi
+	for dir in "$@"; do
+		debug "mkdir $MNTIMAGE$dir"
+		install -d "$MNTIMAGE$dir"
+	done
+}
+
 find_modules_softraid() {
 	if [ -f /etc/mdadm.conf ]; then
 		debug "Finding RAID details using mdadm for rootdev=$1"
@@ -626,11 +639,11 @@ firmware_install_module_pre() {
 	firmware_files="$3"
 
 	debug "Adding Firmwares ($firmware_files) to initrd for module $module"
-	mkdir -p $MNTIMAGE/proc
-	mkdir -p $MNTIMAGE/sys
+	inst_d /proc
+	inst_d /sys
 	# firmware not yet installed
 	if [ ! -f "$MNTIMAGE/lib/firmware/firmware.sh" ]; then
-		mkdir -p $MNTIMAGE/lib/firmware
+		inst_d /lib/firmware
 cat << 'EOF' >> "$MNTIMAGE/lib/firmware/firmware.sh"
 #!/bin/sh -e
 echo 1 > /sys$DEVPATH/loading
@@ -662,8 +675,8 @@ modules_install() {
 	modules="$1"
 
 	for mod in $modules; do
-		MODULEDIR="`dirname "$mod"`"
-		mkdir -p "$MNTIMAGE/lib/modules/$kernel/$MODULEDIR"
+		MODULEDIR=$(dirname "$mod")
+		inst_d "/lib/modules/$kernel/$MODULEDIR"
 		cp -a "/lib/modules/$kernel/$mod" "$MNTIMAGE/lib/modules/$kernel/$mod"
 		gunzip "$MNTIMAGE/lib/modules/$kernel/$mod" 2> /dev/null
 	done
@@ -1028,14 +1041,11 @@ if [ -f "$IMAGE" ]; then
 fi
 
 mkdir -p "$MNTPOINT"
-
-
-mkdir -p "$MNTIMAGE"/{lib,bin,etc,dev,loopfs,var}
-
-
 # We don't need this directory, so let's save space
 rm -rf "$MNTPOINT"/lost+found
 
+inst_d /{lib,bin,etc,dev,loopfs,var}
+
 modules_install "$MODULES"
 
 # mknod'ing the devices instead of copying them works both with and
@@ -1043,8 +1053,7 @@ modules_install "$MODULES"
 mknod "$MNTIMAGE/dev/console" c 5 1
 mknod "$MNTIMAGE/dev/null" c 1 3
 mknod "$MNTIMAGE/dev/zero" c 1 5
-mkdir "$MNTIMAGE/dev/pts"
-mkdir "$MNTIMAGE/dev/shm"
+inst_d /dev/pts /dev/shm
 
 s="$RCFILE"
 ln -s /linuxrc $MNTIMAGE/init
@@ -1088,8 +1097,7 @@ initrd_gen_suspend() {
 	if [ ! -x /usr/sbin/resume ]; then
 		die "/usr/sbin/resume is missing!"
 	fi
-	mkdir -p $MNTIMAGE/etc
-	mkdir -p $MNTIMAGE/dev
+	inst_d /etc /dev
 	resume_dev="$(awk '/^resume device =/ { print $4 } ' /etc/suspend.conf)"
 	inst /dev/snapshot /dev
 	inst $resume_dev /dev
@@ -1099,8 +1107,7 @@ initrd_gen_suspend() {
 }
 
 initrd_gen_tuxonice() {
-	mkdir -p $MNTIMAGE/sys
-	mkdir -p $MNTIMAGE/proc
+	inst_d /sys /proc
 cat << 'EOF' >> "$s"
 mount -t proc none /proc
 mount -t sysfs none /sys
@@ -1146,10 +1153,7 @@ EOF
 
 initrd_gen_udev() {
 	debug "Setting up udev..."
-	mkdir -p $MNTIMAGE/sbin
-	mkdir -p $MNTIMAGE/proc
-	mkdir -p $MNTIMAGE/etc/udev
-	mkdir -p $MNTIMAGE/sys
+	inst_d /sbin /proc /etc/udev /sys
 
 	if [ ! -x /sbin/initrd-udevd ]; then
 		die "/sbin/initrd-udevd not present"
@@ -1192,8 +1196,7 @@ initrd_gen_dmraid() {
 	# always make /dev on tmpfs
 	initrd_gen_tmpfs_dev
 
-	mkdir -p "$MNTIMAGE/sbin"
-	mkdir -p "$MNTIMAGE/sys"
+	inst_d /sbin /sys
 	inst /sbin/dmraid-initrd /sbin/dmraid
 	cat <<-EOF >> "$s"
 	mount -t proc none /proc
@@ -1266,9 +1269,8 @@ initrd_gen_softraid() {
 
 		for f in $cr_dev_list $cr_rootdev $dev_list_extra; do
 			# mkdir in case of devfs name
-			mkdir -p $MNTIMAGE/`dirname $f`
+			inst_d $(dirname $f)
 			[ -e "$MNTIMAGE/$f" ] && continue
-			debug echo "copying $f"
 			# this works fine with and without devfs
 			inst $f $f
 		done
@@ -1333,10 +1335,7 @@ EOF
 initrd_gen_lvm() {
 	debug "Adding LVM support to initrd"
 	inst /sbin/initrd-lvm /bin/lvm
-	mkdir -p $MNTIMAGE/etc
-	mkdir -p $MNTIMAGE/tmp
-	mkdir -p $MNTIMAGE/proc
-	mkdir -p $MNTIMAGE/newroot
+	inst_d /etc /tmp /proc /newroot
 
 	# always make /dev on tmpfs for LVM2
 	if [ "$LVMTOOLSVERSION" = "2" ]; then
@@ -1344,7 +1343,7 @@ initrd_gen_lvm() {
 	fi
 
 	if ! is_yes "$tmpfs_dev"; then
-		mkdir -p $MNTIMAGE/dev/mapper
+		inst_d /dev/mapper
 		mknod $MNTIMAGE/dev/mapper/control c 10 63
 		for device in $PVDEVICES; do
 			# if LVM on RAID then device might be copied already in gen_softraid
@@ -1417,7 +1416,7 @@ EOF
 
 initrd_gen_procdata() {
 	debug "Adding rootfs finding based on root= option support."
-	mkdir -p $MNTIMAGE/proc
+	inst_d /proc
 cat << 'EOF' >> "$s"
 mount -t proc none /proc
 root="$(busybox awk ' /root=\/dev\// { gsub(/.*root=\/dev\//,NIL,$0); gsub(/ .*/,NIL,$0); print $0; } ' /proc/cmdline)"
@@ -1476,7 +1475,7 @@ fi
 [ ! -e "$MNTIMAGE/$rootdev_add" ] && inst $rootdev_add /dev
 
 if [ "$INITRDFS" = "initramfs" ]; then
-	mkdir -p $MNTIMAGE/newroot
+	inst_d /newroot
 	[ ! -e "$MNTIMAGE/$rootdev" ] && inst $rootdev /dev
 	# Parsing root parameter
 	# We support passing root as hda3 /dev/hda3 0303 0x0303 and 303
================================================================

---- gitweb:

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



More information about the pld-cvs-commit mailing list