#!/bin/bash
CPWD=`cd $(dirname $0);pwd`
cd $CPWD
for DEV in `nvme list |egrep "\bSSDPE2KX" |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
		sleep 5
	else 
		echo "$DEV LBA size is already 512B"
	fi
	if [[ "$FW_Ver" != "VDV10170" ]];then
		nvme fw-download /dev/$DEV -f VDV10170_VB1B0172_WFEM01Q0_signed.bin
		nvme fw-activate /dev/$DEV -s 1 -a 1
		nvme reset /dev/$DEV 
		sleep 5
	else 
		echo "$DEV FW is already VDV10170"
	fi
done
