From c0c2c46b35f94de8c3c38a4247b0181d868e8c5b Mon Sep 17 00:00:00 2001 From: Q Date: Sat, 11 Jan 2025 20:42:12 +0200 Subject: [PATCH] mountpoint checker --- bin/is-mount | 1 + files/is-mount | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 120000 bin/is-mount create mode 100755 files/is-mount diff --git a/bin/is-mount b/bin/is-mount new file mode 120000 index 0000000..043c7eb --- /dev/null +++ b/bin/is-mount @@ -0,0 +1 @@ +../files/is-mount \ No newline at end of file diff --git a/files/is-mount b/files/is-mount new file mode 100755 index 0000000..3b01b38 --- /dev/null +++ b/files/is-mount @@ -0,0 +1,45 @@ +#!/bin/bash +set -e +function _help() { + echo ' +Usage: is-mount path + + Checks if path is the mountpoint root folder + + example: is-mount -v /mnt/mountpoint + + -v for verbose output + + if path is a mountpoint: exit 0 + If path is not a mountpoint: exit 10 + if path is missing: exit 1 + ' + exit +} +verbose=0 +for (( i=1; i<=$#; i++ )) +do if [[ "${!i}" = "-h" ]]; then _help; fi + if [[ "${!i}" = "-v" ]]; then verbose=1; continue; fi + if [[ -z "$path1" ]]; then path1="${!i}"; continue; fi +done +if [[ -z "$path1" ]]; then _help; fi + +if [[ ! -e "$path1" ]]; then + echo "No such path '$path1'" + exit 1 +fi + +path1=$( realpath "$path1" ) + +mountpoint1=$( stat -c "%m" "$path1" ) + +if [[ "$path1" = "$mountpoint1" ]]; then + if [[ $verbose -eq 1 ]]; then + echo "$path1 is a mount point" + fi + exit 0 +fi +if [[ $verbose -eq 1 ]]; then + echo "$path1 is not a mount point (it is $mountpoint1)" + fi +exit 10