Debian Codegraph @

debian/checks/blkid

raw
1 #!/bin/sh
2 # this script depends on /sbin/blkid from the util-linux package
3
4 # usage: blkid <device> <fs_type> [<offset>]
5 # <device> may be any device that should be checked.
6 # if no <fs_type> is given, the check fails if no valid filesystem is found.
7 # if <fs_type> is given, the check fails when no filesystem type <fs_type>
8 # is found on the device. if <fs_type> is 'none', the check fails if any
9 # know filesystem is found.
10
11 if test ! -x "/sbin/blkid"; then
12 echo " - WARNING: blkid from util-linux is not available, impossible to run checks."
13 exit 1
14 fi
15
16 dev="$1"
17 fs="$2"
18 offset="${3-}"
19
20 blkid="$(/sbin/blkid -o value -s TYPE -p ${offset:+-O "$offset"} -- "$dev")"
21
22 # blkid output is empty if $dev has an unknown filesystem
23 if [ -z "$blkid" ] && [ -z "$fs" ]; then
24 echo " - The device $dev does not contain a known filesystem${offset:+" at offset $offset"}."
25 exit 1
26 elif [ -n "$blkid" ] && [ "$fs" = "none" ]; then
27 echo " - The device $dev contains a filesystem type $blkid${offset:+" at offset $offset"}."
28 exit 1
29 elif [ -n "$fs" ] && [ "$blkid" != "$fs" ]; then
30 echo " - The device $dev does not contain a filesystem type $fs${offset:+" at offset $offset"}."
31 exit 1
32 fi