commit:     f2e48df4ad02697915037dfbe5fe81411c1750fe
Author:     Fernando Reyes (likewhoa) <design <AT> missionaccomplish <DOT> com>
AuthorDate: Tue Jun  3 17:48:14 2014 +0000
Commit:     Richard Farina <zerochaos <AT> gentoo <DOT> org>
CommitDate: Mon Jun 23 23:11:15 2014 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/genkernel.git;a=commit;h=f2e48df4

Better implementation which was originally done in 946918e & 7a38d63.

---
 defaults/initrd.scripts | 36 ++++++++++++++++++++++++++++++++++++
 defaults/linuxrc        | 38 ++------------------------------------
 2 files changed, 38 insertions(+), 36 deletions(-)

diff --git a/defaults/initrd.scripts b/defaults/initrd.scripts
index 07890ec..52b18b3 100644
--- a/defaults/initrd.scripts
+++ b/defaults/initrd.scripts
@@ -310,6 +310,42 @@ union_insert_modules() {
        done
 }
 
+# Implements RC_NO_UMOUNTS variable into ${CHROOT}/etc/rc.conf for a cleaner 
shutdown process
+# This should really go into /etc/init.d/localmounts but until then we 
manually set this here
+conf_rc_no_umounts() {
+        local conf nomount fnd
+        conf="${CHROOT}/etc/rc.conf"
+        fnd=0
+
+        if nomount=$(grep -n '^[[:blank:]]*RC_NO_UMOUNTS=' $conf); then
+                local i n data cmd IFS
+                IFS='
+'
+                set -- $nomount
+                unset IFS
+
+                for i; do
+                        n=${i%%:*}; i=${i#"$n"}
+                        data=${i#*=}
+
+                        case $data in
+                                "\"$RC_NO_UMOUNTS\""|"'$RC_NO_UMOUNTS'") 
fnd=1;;
+                                *) cmd="$cmd$n d;"
+                        esac
+                done
+
+                if [ -n "$cmd" ]; then
+                        sed -i "${cmd%;}" $conf
+                        test_success "Unable to edit rc.conf"
+                fi
+        fi
+
+        if [ 0 -eq "$fnd" ]; then
+                printf 'RC_NO_UMOUNTS="%s"\n' "$RC_NO_UMOUNTS" >> $conf
+                test_success "Unable to write to rc.conf"
+        fi
+}
+
 # Function to create an ext2 fs on $CHANGESDEV, $CHANGESMNT mountpoint
 create_changefs() {
        local size

diff --git a/defaults/linuxrc b/defaults/linuxrc
index 0e40d16..a6c4806 100644
--- a/defaults/linuxrc
+++ b/defaults/linuxrc
@@ -791,42 +791,8 @@ then
                #sed -e 's|\(.*\s/\s*tmpfs\s*\)defaults\(.*\)|\1defaults,ro\2|' 
/${UNION}/etc/fstab > /${UNION}/etc/fstab.new
                #mv /${UNION}/etc/fstab.new /${UNION}/etc/fstab
 
-                # RC_NO_UMOUNTS variable for a clean shutdown/reboot
-                RC_MOUNTS=$(grep 'RC_NO_UMOUNTS' "${CHROOT}"/etc/rc.conf)
-
-                # Iterate through ${RC_MOUNTS} to find our duplicate(s) and or 
remove obsolete lines when ever
-                # our RC_NO_UMOUNTS variable changes.
-                if [ -n "${RC_MOUNTS}" ]; then
-                        printf '%s\n' ${RC_MOUNTS} |
-                                {
-                                        while read -r mount; do
-                                                # Remove double quotes from 
${mount}
-                                                new_mount=$(echo ${mount} | 
sed 's/"//g')
-
-                                                if [[ "${new_mount}" = 
"RC_NO_UMOUNTS="${RC_NO_UMOUNTS}"" ]]; then
-                                                        RESULTS=false
-                                                else
-                                                        # Escape characters in 
${mounts} for use in sed
-                                                        mount_re=$(echo 
${mount} | sed -e 's/\//\\\//g' -e 's/\&/\\\&/g')
-
-                                                        # Remove non matching 
pattern
-                                                        sed -i 
"/${mount_re}/d" "${CHROOT}"/etc/rc.conf
-
-                                                        RESULTS=true
-                                                fi
-                                        done
-
-                                        # no RC_NO_UMOUNTS match found
-                                        if ${RESULTS}; then return 1;fi
-                                }
-                else
-                        echo "RC_NO_UMOUNTS=\"${RC_NO_UMOUNTS}\"">> 
"${CHROOT}"/etc/rc.conf
-                fi
-
-                # An RC_NO_UMOUNTS was not found that matches our current one
-                if [ $? -eq 1 ]; then
-                        echo "RC_NO_UMOUNTS=\"${RC_NO_UMOUNTS}\"">> 
"${CHROOT}"/etc/rc.conf
-                fi
+                # Function to handle the RC_NO_UMOUNTS variable in 
${CHROOT}/etc/rc.conf
+                conf_rc_no_umounts
 
                 # Fstab change for aufs
                 test ! $(grep -o ^aufs "${CHROOT}"/etc/fstab) &&

Reply via email to