From f4285363d0cafb84737567ebcd9615e7e875297b Mon Sep 17 00:00:00 2001 From: Demian Ginther <st.diluted@gmail.com> Date: Tue, 12 Mar 2019 14:00:01 -0600 Subject: [PATCH] Simplify the check Instead of making some if statements for more than one case, how about this approach? Get the path and UUID of the Docker Home Dir Check that UUID against the parent paths of the Docker Home Dir If the UUID matches a parent path, we are not on our own volume. --- tests/1_host_configuration.sh | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/tests/1_host_configuration.sh b/tests/1_host_configuration.sh index ced4511..047e66b 100644 --- a/tests/1_host_configuration.sh +++ b/tests/1_host_configuration.sh @@ -18,27 +18,34 @@ check_1_1() { totalChecks=$((totalChecks + 1)) - if [[ "$(docker info -f '{{ .SecurityOptions }}')" =~ .*userns.* ]]; then - if mountpoint -q -- "$(dirname "$(docker info -f '{{ .DockerRootDir }}')")" >/dev/null 2>&1; then - pass "$check_1_1" - resulttestjson "PASS" - currentScore=$((currentScore + 1)) + DOCKER_HOME="$(docker info -f '{{ .DockerRootDir }}')" + DOCKER_MNT="$(findmnt -fnT $DOCKER_HOME|awk '{print $1}')" + MNT_UUID="$(findmnt -o UUID -fnT $DOCKER_HOME)" + DEPTH="$(echo $DOCKER_MNT | grep -o / | wc -l)" + UUID_ARRAY=() + + for ((i=$DEPTH-1;i>0;i--)); do + EXPANSION="$(printf %${i}s | sed 's/ /\/\*/g')" + UUID_ARRAY[$i]="$(findmnt -o UUID -fnT ${DOCKER_MNT%$EXPANSION})" + done + + for i in "${UUID_ARRAY[@]}"; do + if [ "$MNT_UUID" == "$i" ]; then + WARN=1 + break 2 else + continue + fi + done + if [[ $WARN == 1 ]]; then warn "$check_1_1" resulttestjson "WARN" currentScore=$((currentScore - 1)) - fi - else - if mountpoint -q -- "$(docker info -f '{{ .DockerRootDir }}')" >/dev/null 2>&1; then + else pass "$check_1_1" resulttestjson "PASS" currentScore=$((currentScore + 1)) - else - warn "$check_1_1" - resulttestjson "WARN" - currentScore=$((currentScore - 1)) fi - fi } # 1.2