#!/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
	
	DEV_INFO=$(nvme list | grep $DEV)
	
	# 提取LBA大小,只保留数字
	LBA_Size=$(echo "$DEV_INFO" | awk '{print $11}' | sed 's/[^0-9]//g')
	
	# 获取固件版本
	FW_Ver=$(echo "$DEV_INFO" | awk '{print $NF}')	
	
	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" != "FF001316" ]];then
		nvme fw-download /dev/$DEV -f FF001316_DPH311T5T006T4.dfw
		nvme fw-commit /dev/$DEV -s 1 -a 1 && sleep 5s
	else 
		echo "$DEV FW is already FF001316"
	fi
done

