#!/bin/sh
set -e

oldpath=/sbin/scsi_id
newpath=/lib/udev/scsi_id

if [ -e "$newpath" ]; then
	cmd="$newpath"
else
	if [ -e "$oldpath" ]; then
		cmd="$oldpath"
	else
		exit 1
	fi
fi

base_uid=`$cmd -g -u -s /block/$1 2> /dev/null`
if echo $1 | grep -q '^.*\/[^0-9]*[0-9]*$' > /dev/null 2>&1 ; then
	part=`echo $1 | sed 's/^.*\/[^0-9]*\([0-9]*\)$/\1/'`
	echo GNBD-${part}-${base_uid}
else
	echo GNBD--${base_uid}
fi
