From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-796905-garchives=archives.gentoo.org@lists.gentoo.org>
Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80])
	by finch.gentoo.org (Postfix) with ESMTP id 1CEE1138C9D
	for <garchives@archives.gentoo.org>; Wed, 29 Apr 2015 19:04:15 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id B317AE086D;
	Wed, 29 Apr 2015 19:04:14 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id 2223AE0850
	for <gentoo-commits@lists.gentoo.org>; Wed, 29 Apr 2015 19:04:14 +0000 (UTC)
Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52])
	(using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 2DDFB3408A0
	for <gentoo-commits@lists.gentoo.org>; Wed, 29 Apr 2015 19:04:13 +0000 (UTC)
Received: from localhost.localdomain (localhost [127.0.0.1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id 9650B9A8
	for <gentoo-commits@lists.gentoo.org>; Wed, 29 Apr 2015 19:04:07 +0000 (UTC)
From: "Richard Farina" <zerochaos@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: 8bit
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "Richard Farina" <zerochaos@gentoo.org>
Message-ID: <1430328705.5a62af115cf85e15fbac4f35d98af2a5bf34d004.zerochaos@gentoo>
Subject: [gentoo-commits] proj/genkernel:aufs commit in: defaults/
X-VCS-Repository: proj/genkernel
X-VCS-Files: defaults/initrd.defaults defaults/linuxrc
X-VCS-Directories: defaults/
X-VCS-Committer: zerochaos
X-VCS-Committer-Name: Richard Farina
X-VCS-Revision: 5a62af115cf85e15fbac4f35d98af2a5bf34d004
X-VCS-Branch: aufs
Date: Wed, 29 Apr 2015 19:04:07 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Archives-Salt: 51d37bd2-66b5-44af-863c-8248a0495c94
X-Archives-Hash: 748cdcd5bda9e4f2c5f4c39a69171d2c

commit:     5a62af115cf85e15fbac4f35d98af2a5bf34d004
Author:     Fernando Reyes (likewhoa) <design <AT> missionaccomplish <DOT> com>
AuthorDate: Fri May 30 00:51:08 2014 +0000
Commit:     Richard Farina <zerochaos <AT> gentoo <DOT> org>
CommitDate: Wed Apr 29 17:31:45 2015 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=5a62af11

Enhanced the shutdown process and changed from using ${UNION} to ${CHROOT} to
better understand the logic behind things as CHROOT is set to ${UNION} anyways.

RC_NO_UMOUNTS is more dynamic now and should scale up.

 defaults/initrd.defaults |  1 +
 defaults/linuxrc         | 45 +++++++++++++++++++++++++++++++--------------
 2 files changed, 32 insertions(+), 14 deletions(-)

diff --git a/defaults/initrd.defaults b/defaults/initrd.defaults
index aa9f85c..9937e00 100755
--- a/defaults/initrd.defaults
+++ b/defaults/initrd.defaults
@@ -58,6 +58,7 @@ KSUFF='.ko'
 REAL_ROOT=''
 CONSOLE='/dev/console'
 NEW_ROOT='/newroot'
+RC_NO_UMOUNTS="/newroot|/newroot/mnt/changesdev|/mnt/overlay|/mnt/livecd|/mnt/cdrom|/.unions/memory|/.unions/memory/xino"
 CDROOT='0'
 CDROOT_DEV=''
 CDROOT_TYPE='auto'

diff --git a/defaults/linuxrc b/defaults/linuxrc
index 0a91c58..5d4d2a1 100644
--- a/defaults/linuxrc
+++ b/defaults/linuxrc
@@ -805,24 +805,38 @@ then
 
 	if [ "${USE_AUFS_NORMAL}" -eq '1' ]
 	then
-		union_insert_dir ${UNION} ${NEW_ROOT}/${FS_LOCATION}
+		union_insert_dir ${CHROOT} ${NEW_ROOT}/${FS_LOCATION}
 
 		# Make sure fstab notes livecd is mounted ro.  Makes system skip remount which fails on aufs dirs.
 		# TODO: remounting all tmpfs as RO seems weird, can we be more specific?
-		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
+		#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
-                test ! $(grep 'RC_NO_UMOUNTS="/newroot|/newroot/mnt/aufs|\
-/newroot/mnt/changesdev|/mnt/livecd|/mnt/cdrom|/.unions/\
-memory|/.unions/memory/xino"' "${UNION}"/etc/rc.conf) &&
-                        echo "RC_NO_UMOUNTS=\"/newroot|/newroot/mnt/aufs|"\
-"/newroot/mnt/changesdev|/mnt/livecd|/mnt/cdrom|"\
-"/.unions/memory|/.unions/memory/xino\"">> "${UNION}"/etc/rc.conf
+                RC_MOUNTS=$(grep 'RC_NO_UMOUNTS' "${CHROOT}"/etc/rc.conf)
+                RESULTS=false
+
+                # Iterate through ${RC_MOUNTS} to find our duplicate(s) and or remove obsolete lines when ever
+                # our RC_NO_UMOUNTS variable changes.
+                printf '%s\n' ${RC_MOUNTS} | while read -r mount; do
+                        if [[ "${mount}" = "RC_NO_UMOUNTS=\"${RC_NO_UMOUNTS}\"" ]]; then
+                                RESULTS=true
+                        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
+                        fi
+                done
+
+                if ! ${RESULTS}; then
+                        echo 'RC_NO_UMOUNTS="/newroot|/newroot/mnt/changesdev|/mnt/overlay|/mnt/livecd|/mnt/cdrom|/.unions/memory|/.unions/memory/xino"'>> "${CHROOT}"/etc/rc.conf
+                fi
 
                 # Fstab change for aufs
-                test ! $(grep aufs "${UNION}"/etc/fstab) &&
-                        echo "aufs / aufs defaults 0 0" > "${UNION}"/etc/fstab
+                test ! $(grep -o ^aufs "${CHROOT}"/etc/fstab) &&
+                        echo "aufs / aufs defaults 0 0" > "${CHROOT}"/etc/fstab
 
 		warn_msg "Adding all modules in $MODULESD/modules/"
 		if [ -z "${MODULESD}" ]
@@ -834,9 +848,12 @@ memory|/.unions/memory/xino"' "${UNION}"/etc/rc.conf) &&
 			union_insert_modules ${NEW_ROOT}/mnt/modulesd
 		fi
 
-                mkdir -p "${UNION}"/newroot/mnt/aufs
-                test ${AUFS_CHANGES} && test ! -d "${UNION}"/newroot/mnt/changesdev &&
-                        mkdir "${UNION}"/newroot/mnt/changesdev
+                # Create the directories for our new union mounts
+                test ! -d "${CHROOT}${NEW_ROOT}" && mkdir -p "${CHROOT}${NEW_ROOT}"
+
+                if ${AUFS_CHANGES} && [ ! -d "${CHROOT}${NEW_ROOT}/mnt/changesdev" ]; then
+                        mkdir -p "${CHROOT}${NEW_ROOT}/mnt/changesdev"
+                fi
 	fi
 
 	# Unpacking additional packages from NFS mount