#!/bin/bash

VDEV_ID=/etc/vdev_id.conf
storcli=/opt/MegaRAID/storcli/storcli64

CONTROLLER_COUNT=$($storcli show ctrlcount | grep "Controller Count" | awk '{print $4}' )
echo "# by-vdev" > $VDEV_ID
echo "# name     fully qualified or base name of device link" >> $VDEV_ID
i=0
while [ $i -lt $CONTROLLER_COUNT ];do
        DRIVE_COUNT=$($storcli /c$i show | grep "Physical Drives" | awk '{print $4}')
        if [ -z $DRIVE_COUNT ]; then DRIVE_COUNT=0 ; fi
        CARD_TYPE=$($storcli /c$i show | grep "Product Name" | cut -d = -f 2)
        j=0
        while [ $j -lt $DRIVE_COUNT ];do
                echo $CARD_TYPE | grep 9361 >/dev/null ##Change/add for other HWRAID
                if [ $? -eq 0 ];then
                        WWN=$($storcli /c$i/e252/s$j show all | grep WWN | awk '{print $3}')
                else
                        WWN=$($storcli /c$i/s$j show all | grep WWN | awk '{print $3}')
                fi
                echo "alias $(expr $i + 1)-$(expr $j + 1)       wwn-0x$WWN" >> $VDEV_ID
                let j=j+1
        done
        let i=i+1
done
cat $VDEV_ID
udevadm trigger

