#!/bin/bash

shopt -s nullglob nocaseglob

while [ ! -z "$1" ]; do

  # link 
  l=""
  # device file, notation /dev/sda1 with "/dev/" stripped off
  d=""
  # same like $d if matched
  f=""

  case "$1" in
	-a)
	exec "$0" /dev/sd*
	;;
	/dev/disk/by-id/*)
	  $0 $( readlink -f "$1" )
	  shift
	  continue
	;;
	/dev/*)
	  d=${1##/dev/}
	;;
	*)
	  d="$1"
	;;
  esac

  d=$( basename "$d")

  for i in /dev/disk/by-id/*; do
    case "$i" in
	*/by-id/sata-*)
	    continue
	;;
	*/by-id/edd*|*/by-id/wwn*)
	    continue
	;;
	*/by-id/dm-name-*|*/by-id/nvme*|*/by-id/ata-*)
	    f=$( readlink -f "$i")
	    f=$( basename "$f" )
            if [ "$f" = "$d" ]; then
	        l="$i"
		first=1
	        break
	    fi
	;;
	*)
	;;
    esac
  done

  if [ ! -z "$l" ]; then
    if [ ! -z "$first" ]; then
      echo "------------------------------------------------------------"
    fi
    echo "/dev/$d" "$l"
    if [ -f /etc/crypttab ]; then
          c=$( grep "$l" /etc/crypttab )
          if [ ! -z "$c" ]; then
            echo "crypttab:"
            echo "$c"
          fi
    fi
  fi

  shift
done
