un_blkid 832 B

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