~siretart/cryptsetup/debian

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/sh
# this script depends on /lib/udev/vol_id from the udev package

# usage: un_vol_id <device> <fs_type>
# <device> may be any device that should be checked.
# if no <fs_type> is given, the check fails for any valid filesystem
# if <fs_type> is given, the check fails when a filesystem type <fs_type>
# is found on the device.

# note that the 'minix' fs is filtered out if checking for any valid fs,
# as it has been reported that this fs my be detected erroneously by vol_id.

if test ! -x "/lib/udev/vol_id"; then
  echo " - WARNING: vol_id from udev is not available, impossible to run checks."
  exit 0
fi

dev=$1
fs=$2

vol_id=`/lib/udev/vol_id -t $dev 2>&1`

if [ "$vol_id" != "$dev: unknown volume type" ] && [ "$vol_id" != "minix" ] && [ -z "$fs" ]; then
  echo " - The device $dev contains a valid filesystem type $vol_id."
  exit 1
elif [ -n "$fs" ] && [ "$vol_id" = "$fs" ]; then
  echo " - The device $dev contains a filesystem type $fs."
  exit 1
fi