Author: glen
Date: Tue Oct 23 17:16:51 2007
New Revision: 8841

Modified:
   geninitrd/trunk/geninitrd
Log:
- add inst_d() utility function to make dirs

Modified: geninitrd/trunk/geninitrd
==============================================================================
--- geninitrd/trunk/geninitrd   (original)
+++ geninitrd/trunk/geninitrd   Tue Oct 23 17:16:51 2007
@@ -264,6 +264,9 @@
        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 @@
        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_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="$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 @@
 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 @@
 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 @@
        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_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 @@
 
 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 @@
        # 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 @@
 
                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 @@
 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 @@
        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 @@
 
 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 @@
 [ ! -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
_______________________________________________
pld-cvs-commit mailing list
[email protected]
http://lists.pld-linux.org/mailman/listinfo/pld-cvs-commit

Reply via email to