#!/bin/bash
which nvme &>/dev/null
if [ $? -ne 0 ];then
        yum install nvme-cli -y
fi
for DEV in `nvme list |egrep "\bSSDPE21K" |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 $Model LBA size is already 512B"
        fi
        if [[ "$FW_Ver" != "E2010485" ]];then
        	nvme fw-download /dev/$DEV -f E2010485_EB3B0438_WFEM01M0_signed.bin 
                nvme fw-commit /dev/$DEV -s 1 -a 1
                sleep 5
        else 
               	echo "$DEV $Model FW is already E2010485"
        fi
done
