support installing Chromium OS chroot in another chroot

The detection of whether we are inside the Chromium OS build chroot is
making a false positive when run inside Crouton which is itself a
Ubuntu chroot.
Let's filter out all Debian derivative chroot and check only for a
genuine Chromium OS chroot.

BUG=none
TEST=on Pixel in dev mode, run cros_sdk in the Crouton chroot.
CQ-DEPEND=I3c143e85c141e2def038fb859c90bea7003fc875

Change-Id: I723fc57805d3891d00a111547f9aaa33231aa9ea
Reviewed-on: https://chromium-review.googlesource.com/188071
Commit-Queue: Vincent Palatin <vpalatin@chromium.org>
Tested-by: Vincent Palatin <vpalatin@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/bin/cros_image_to_target.py b/bin/cros_image_to_target.py
index 75e7ef1..5dfc11d 100755
--- a/bin/cros_image_to_target.py
+++ b/bin/cros_image_to_target.py
@@ -199,7 +199,7 @@
     return os.path.join(self.cros_root, filename)
 
   def ChrootPath(self, filename):
-    if os.path.exists('/etc/debian_chroot'):
+    if os.path.exists('/etc/cros_chroot_version'):
       return filename
     else:
       return self.CrosUtilsPath(os.path.join('..', '..', 'chroot',
diff --git a/common.sh b/common.sh
index da305ff..283388b 100644
--- a/common.sh
+++ b/common.sh
@@ -37,7 +37,7 @@
 : ${SCRIPT_NAME:=$(basename "$0")}
 
 # Detect whether we're inside a chroot or not
-if [[ -e /etc/debian_chroot ]]; then
+if [[ -e /etc/cros_chroot_version ]]; then
   INSIDE_CHROOT=1
 else
   INSIDE_CHROOT=0
diff --git a/sdk_lib/make_chroot.sh b/sdk_lib/make_chroot.sh
index 2ce8af9..d1dd6a3 100755
--- a/sdk_lib/make_chroot.sh
+++ b/sdk_lib/make_chroot.sh
@@ -345,6 +345,7 @@
 CROSSDEV_OVERLAY="${OVERLAYS_ROOT}/crossdev"
 CHROOT_OVERLAY="${OVERLAYS_ROOT}/chromiumos"
 CHROOT_STATE="${FLAGS_chroot}/etc/debian_chroot"
+CHROOT_VERSION="${FLAGS_chroot}/etc/cros_chroot_version"
 
 # Pass proxy variables into the environment.
 for type in http ftp all; do
@@ -390,6 +391,12 @@
   rm -f "$FLAGS_chroot/etc/"make.{globals,conf.user}
 fi
 
+# Ensure that we properly detect when we are inside the chroot.
+# We'll force this to the latest version at the end as needed.
+if [[ ! -e ${CHROOT_VERSION} ]]; then
+  echo "0" > "${CHROOT_VERSION}"
+fi
+
 # Set up users, if needed, before mkdir/mounts below.
 [ -f $CHROOT_STATE ] || init_users