46 lines
909 B
Bash
Executable File
46 lines
909 B
Bash
Executable File
#!/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
|