#!/bin/bash
which nvme &>/dev/null
if [ $? -ne 0 ];then
	yum install nvme-cli -y
fi
for DEV in `nvme list |egrep "\bDPH311" |awk '{print $1}' |awk -F"/" '{print $3}' |sed 's/n1$//g'`;do
	LBA_Size=`smartctl -a /dev/$DEV |awk '/Namespace 1 Formatted LBA Size/{print $NF}' |sed 's/\s*//g'`
	FW_Ver=`smartctl -a /dev/$DEV |awk '/Firmware Version/{print $NF}' |sed 's/\s*//g'`
	if [[ "$LBA_Size" != "512" ]];then
		nvme format /dev/$DEV -l 0
		modprobe -r nvme
		sleep 5s
		modprobe nvme
		sleep 5s
	else 
		echo "$DEV LBA size is already 512B"
	fi
	if [[ "$FW_Ver" != "FF001219" ]];then
		nvme fw-download /dev/$DEV -f FF001219_Patch5_U2_6.4T.dfw
		nvme fw-commit /dev/$DEV -s 1 -a 3
		sleep 5
	else 
		echo "$DEV FW is already FF001219"
	fi
done
