#!/bin/bash
CPWD=$(cd `dirname $0`;pwd)
cd $CPWD
if [[ -e /usr/sbin/hioadm ]];then
	echo -e "huawei nvme ssd tool hioadm is already installed"
else
	rpm -Uvh hioadm-5.0.3.9-1.x86_64.rpm
fi
for DEV in `nvme list |egrep "\bHWE52P43" |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 5
		modprobe nvme
		sleep 5
	else 
		echo "$DEV LBA size is already 512B"
	fi
	if [[ ${FW_version} != 3232 ]];then
		echo y |hioadm updatefw -d $DEV -f ES3000V5_FW_3232.bin -a 1
	fi
done
