IMP: improve partition detection in container

fix #27
This commit is contained in:
Thibault Ayanides 2021-01-25 14:44:31 +01:00 committed by Thibault Ayanides
parent 2d6550fb13
commit 449c695415

View File

@ -391,12 +391,20 @@ is_kernel_option_enabled() {
is_a_partition() { is_a_partition() {
local PARTITION=$1 local PARTITION=$1
FNRET=128 FNRET=128
if grep "[[:space:]]$1[[:space:]]" /etc/fstab | grep -vqE "^#"; then if [ ! -f /etc/fstab ] || [ -n "$(sed '/^#/d' /etc/fstab)" ]; then
debug "$PARTITION found in fstab" debug "/etc/fstab not found or empty, searching mountpoint"
FNRET=0 if mountpoint "$PARTITION" | grep -qE ".*is a mountpoint.*"; then
FNRET=0
fi
else else
debug "Unable to find $PARTITION in fstab" if grep "[[:space:]]$1[[:space:]]" /etc/fstab | grep -vqE "^#"; then
FNRET=1 debug "$PARTITION found in fstab"
FNRET=0
else
debug "Unable to find $PARTITION in fstab"
FNRET=1
fi
fi fi
} }
@ -416,18 +424,23 @@ is_mounted() {
has_mount_option() { has_mount_option() {
local PARTITION=$1 local PARTITION=$1
local OPTION=$2 local OPTION=$2
if grep "[[:space:]]${PARTITION}[[:space:]]" /etc/fstab | grep -vE "^#" | awk '{print $4}' | grep -q "bind"; then if [ ! -f /etc/fstab ] || [ -n "$(sed '/^#/d' /etc/fstab)" ]; then
local actual_partition debug "/etc/fstab not found or empty, readin current mount options"
actual_partition="$(grep "[[:space:]]${PARTITION}[[:space:]]" /etc/fstab | grep -vE "^#" | awk '{print $1}')" has_mounted_option "$PARTITION" "$OPTION"
debug "$PARTITION is a bind mount of $actual_partition"
PARTITION="$actual_partition"
fi
if grep "[[:space:]]${PARTITION}[[:space:]]" /etc/fstab | grep -vE "^#" | awk '{print $4}' | grep -q "$OPTION"; then
debug "$OPTION has been detected in fstab for partition $PARTITION"
FNRET=0
else else
debug "Unable to find $OPTION in fstab for partition $PARTITION" if grep "[[:space:]]${PARTITION}[[:space:]]" /etc/fstab | grep -vE "^#" | awk '{print $4}' | grep -q "bind"; then
FNRET=1 local actual_partition
actual_partition="$(grep "[[:space:]]${PARTITION}[[:space:]]" /etc/fstab | grep -vE "^#" | awk '{print $1}')"
debug "$PARTITION is a bind mount of $actual_partition"
PARTITION="$actual_partition"
fi
if grep "[[:space:]]${PARTITION}[[:space:]]" /etc/fstab | grep -vE "^#" | awk '{print $4}' | grep -q "$OPTION"; then
debug "$OPTION has been detected in fstab for partition $PARTITION"
FNRET=0
else
debug "Unable to find $OPTION in fstab for partition $PARTITION"
FNRET=1
fi
fi fi
} }