[explorer/machine_type] Implement chroot detection

This commit is contained in:
Dennis Camera 2021-07-31 22:01:28 +02:00
parent 23fbfaf035
commit 4a05669765

View file

@ -53,6 +53,21 @@ uname_s=$(uname -s)
is_command() { command -v "$1" >/dev/null 2>&1; } is_command() { command -v "$1" >/dev/null 2>&1; }
files_same() {
# shellcheck disable=SC2012
LC_ALL=C df -P "$1" "$2" 2>/dev/null | {
read -r _ # skip header line
read -r fs1 _ _ _ _ mp1
read -r fs2 _ _ _ _ mp2
test "${fs1}" = "${fs2}" -a "${mp1}" = "${mp2}" || return 1
} &&
ls -1Ldi "$1" "$2" 2>/dev/null | {
read -r ino1 _
read -r ino2 _
test "${ino1}" = "${ino2}" || return 1
}
}
is_oneof() ( is_oneof() (
x=$1; shift x=$1; shift
for y for y
@ -128,6 +143,32 @@ detected_layer() {
} }
# Check for chroot
has_chroot_systemd() {
is_command systemd-detect-virt && systemd-detect-virt --help | grep -q -e '^ -r'
}
check_chroot_systemd() {
systemd-detect-virt -r
}
has_chroot_debian_ischroot() {
is_command ischroot
}
check_chroot_debian_ischroot() {
ischroot --default-false
}
has_chroot_procfs() {
test -d /proc/
}
check_chroot_procfs() {
test -e /proc/1/root && ! files_same /proc/1/root /
}
# Check for container # Check for container
has_ct_systemd() { has_ct_systemd() {
@ -881,6 +922,18 @@ run_stage() {
} }
# Execute chroot stages
for stage in \
procfs debian_ischroot systemd
do
run_stage chroot ${stage} || continue
detected_layer 'chroot'
echo chroot
break
done
# Execute container stages # Execute container stages
for stage in \ for stage in \