commit:     c7ae28126edd1fcf2144e93a6c73f7b07bd79c48
Author:     Fernando Reyes (likewhoa) <design <AT> missionaccomplish <DOT> com>
AuthorDate: Wed Jun 25 16:12:11 2014 +0000
Commit:     Richard Farina <zerochaos <AT> gentoo <DOT> org>
CommitDate: Thu Jun 26 14:03:37 2014 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/genkernel.git;a=commit;h=c7ae2812

More coding style changes to two of the union_* functions. LC_COLLATE=C
is introduced to allow globbing since we never want to parse ls.
Introduced a helper function for union_insert_modules as well.

---
 defaults/initrd.defaults |  2 ++
 defaults/initrd.scripts  | 44 +++++++++++++++++++++++++++++---------------
 2 files changed, 31 insertions(+), 15 deletions(-)

diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults
index 67b0d28..93a40dd 100755
--- a/defaults/initrd.defaults
+++ b/defaults/initrd.defaults
@@ -12,6 +12,8 @@ BAD="\033[31;1m"
 BOLD="\033[1m"
 GOOD="\033[32;1m"
 
+# Sets the default collation order
+LC_COLLATE=C
 # From KNOPPIX LINUXRC
 # Reset fb color mode
 RESET="]R"

diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts
index d87bb4e..3411c18 100644
--- a/defaults/initrd.scripts
+++ b/defaults/initrd.scripts
@@ -287,27 +287,41 @@ mount_sysfs() {
 #
 union_insert_dir() {
        # Always mount it over the precedent (add:1:)
-       mount -n -o remount,add:1:${2}=rr aufs ${1}
-       if [ $? = '0' ]
-       then
-               good_msg "Addition of ${2} to ${1} successful"
+       if mount -n -o "remount,add:1:$2=rr" aufs "$1"; then
+                good_msg "Addition of $2 to $1 successful"
        fi
 }
 
 # Insert all modules found in $1, usually ${CDROOT_PATH}
 # added to allow users to add their own apps.
 union_insert_modules() {
-       for module in $(ls ${NEW_ROOT}/${1}/modules/*.mo 2>/dev/null| sort)
-       do
-               mkdir -p ${MEMORY}/modules/$(basename ${module} .mo)
-               union_insert_dir $UNION ${MEMORY}/modules/$(basename ${module} 
.mo)
-       done
-       for module in $(ls ${NEW_ROOT}/${1}/modules/*.lzm 2>/dev/null| sort)
-       do
-               mkdir -p ${MEMORY}/modules/$(basename ${module} .lzm)
-               mount -o loop,ro ${module} ${MEMORY}/modules/$(basename 
${module} .lzm)
-               union_insert_dir $UNION ${MEMORY}/modules/$(basename ${module} 
.lzm)
-       done
+        local module
+
+        for module in "$NEW_ROOT/$1/modules/"*.mo; do
+                union_mod "$module" || bad_msg "Unable to load module: 
'$module'"
+        done
+
+        for module in "$NEW_ROOT/$1/modules/"*.lzm; do
+                union_mod "$module" lzm || bad_msg "Unable to load module: 
'$module'"
+        done
+}
+
+# Helper function for union_insert_modules()
+union_mod() {
+        [ -e "$1" ] || return 0
+
+        local mod
+
+        mod=${1##*/}
+        mod=${mod%.*}
+
+        mkdir -p "$MEMORY/modules/$mod" || return
+
+        if [ lzm = "$2" ]; then
+                 mount -o loop,ro "$1" "$MEMORY/modules/$mod"
+        fi
+
+        union_insert_dir "$UNION" "$MEMORY/modules/$mod"
 }
 
 # Implements RC_NO_UMOUNTS variable into ${CHROOT}/etc/rc.conf for a cleaner 
shutdown process

Reply via email to