#!/bin/bash
# Managed by imaging/driving_os/roles/tftpboot/

# Expects $1 to be the kernel device node (e.g. /dev/sdc)
# Note: any extra output will create extra symlinks

device_letter=${1#/dev/sd}
device_index=$(printf '%d\n' "'$device_letter")
let "device_index=device_index-96"

for DEVICE in /dev/sd? ; do
    if [ "$DEVICE" \< "$1" ] ; then
        udevadm info $DEVICE | grep usb > /dev/null && let "device_index--"
    fi
done
echo $device_index
