From 449c695415af9d697cb046247867078a6dcf01e1 Mon Sep 17 00:00:00 2001 From: Thibault Ayanides Date: Mon, 25 Jan 2021 14:44:31 +0100 Subject: [PATCH] IMP: improve partition detection in container fix #27 --- lib/utils.sh | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) diff --git a/lib/utils.sh b/lib/utils.sh index d30f948..3421604 100644 --- a/lib/utils.sh +++ b/lib/utils.sh @@ -391,12 +391,20 @@ is_kernel_option_enabled() { is_a_partition() { local PARTITION=$1 FNRET=128 - if grep "[[:space:]]$1[[:space:]]" /etc/fstab | grep -vqE "^#"; then - debug "$PARTITION found in fstab" - FNRET=0 + if [ ! -f /etc/fstab ] || [ -n "$(sed '/^#/d' /etc/fstab)" ]; then + debug "/etc/fstab not found or empty, searching mountpoint" + if mountpoint "$PARTITION" | grep -qE ".*is a mountpoint.*"; then + FNRET=0 + fi else - debug "Unable to find $PARTITION in fstab" - FNRET=1 + if grep "[[:space:]]$1[[:space:]]" /etc/fstab | grep -vqE "^#"; then + debug "$PARTITION found in fstab" + FNRET=0 + else + debug "Unable to find $PARTITION in fstab" + FNRET=1 + fi + fi } @@ -416,18 +424,23 @@ is_mounted() { has_mount_option() { local PARTITION=$1 local OPTION=$2 - if grep "[[:space:]]${PARTITION}[[:space:]]" /etc/fstab | grep -vE "^#" | awk '{print $4}' | grep -q "bind"; then - 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 + if [ ! -f /etc/fstab ] || [ -n "$(sed '/^#/d' /etc/fstab)" ]; then + debug "/etc/fstab not found or empty, readin current mount options" + has_mounted_option "$PARTITION" "$OPTION" else - debug "Unable to find $OPTION in fstab for partition $PARTITION" - FNRET=1 + if grep "[[:space:]]${PARTITION}[[:space:]]" /etc/fstab | grep -vE "^#" | awk '{print $4}' | grep -q "bind"; then + 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 }