mountpoint checker

This commit is contained in:
Q
2025-01-11 20:42:12 +02:00
parent e50a14e170
commit c0c2c46b35
2 changed files with 46 additions and 0 deletions

1
bin/is-mount Symbolic link
View File

@@ -0,0 +1 @@
../files/is-mount

45
files/is-mount Executable file
View File

@@ -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