[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[lmi-commits] [lmi] master 502ddd3 3/3: Improve (s)chroot detection
From: |
Greg Chicares |
Subject: |
[lmi-commits] [lmi] master 502ddd3 3/3: Improve (s)chroot detection |
Date: |
Sun, 16 Feb 2020 18:56:05 -0500 (EST) |
branch: master
commit 502ddd37d339099f21f0a25ca3562bf8df4a4d21
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>
Improve (s)chroot detection
There is no simple and portable way to determine whether a script is
running in a chroot. Outside a chroot, 'ls -di /' prints "2" for ext4,
but "64" for a particular server with an XFS filesystem using LVM; it's
unknown what it might print in general, but "32" is also reported.
Because the 'lmi_setup*.sh' scripts use only schroot, it's better to
detect schroot directly, by looking for a variable it always defines
and assuming that no one is so irrational as to define it outside a
chroot environment.
---
lmi_setup_inc.sh | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/lmi_setup_inc.sh b/lmi_setup_inc.sh
index 1cf1914..bbd2196 100755
--- a/lmi_setup_inc.sh
+++ b/lmi_setup_inc.sh
@@ -61,7 +61,7 @@ fi
assert_chrooted()
{
-if [ "$(ls -di /)" = "2 /" ]; then
+if [ -z "$SCHROOT_CHROOT_NAME" ]; then
echo "Must be run in chroot."
exit 1
fi
@@ -69,7 +69,7 @@ fi
assert_not_chrooted()
{
-if [ "$(ls -di /)" != "2 /" ]; then
+if [ -n "$SCHROOT_CHROOT_NAME" ]; then
echo "Must not be run in chroot."
exit 1
fi