#!/bin/bash
#Author:Terrence.Zhou@ucloud.cn
#Date:7/14/2021
#Update Seagate Makara_plus series ST8000NM0055 fw distinguishing from common and customeried for ali fw version 
#Author:carl.jia
#Date:10/21/2024
#Modify function  lsi_mptsas_hdd_ST8000NM0055_upd() and write firmware SN05

CPWD=`cd $(dirname $0);pwd`
cd $CPWD
rm -rf *_map
lsi_megaraid_hdd_ST8000NM0055_upd(){
for i in `/opt/MegaRAID/storcli/storcli64 show all |grep -A 10 "Ctl Model" |grep -B 10 "Ctl=Controller Index" |sed -n '/^-/,/-$/p' |grep -v "^-" |awk '{print $1}' |sed '/^\s*$/d'`
do
	/opt/MegaRAID/storcli/storcli64 /c$i/eall/sall show |grep "HDD" |awk '{print $1,$(NF-2)}' > ${i}_lsi_hdd_map
	for j in `seq 1 $(cat ${i}_lsi_hdd_map |wc -l)`
	do
	Model=$(sed -n "$j"p ${i}_lsi_hdd_map |awk '{print $2}')
	EID=$(sed -n "$j"p ${i}_lsi_hdd_map |awk '{print $1}' |awk -F":" '{print $1}')
 	SID=$(sed -n "$j"p ${i}_lsi_hdd_map |awk '{print $1}' |awk -F":" '{print $2}')
	FW_Ver=$(/opt/MegaRAID/storcli/storcli64 /c$i/e${EID}/s${SID} show all  |grep "Firmware Revision" |awk '{print $NF}')
	match_model=`sed -n 1p ST8000NM0055_upd_list |awk '{print $2}'`
	match_fw_ver_common=`sed -n 1p ST8000NM0055_upd_list |awk '{print $3}'`
	match_fw_ver_ali=`sed -n 1p ST8000NM0055_upd_list |awk '{print $3}'`
	upd_fw_common=`sed -n 1p ST8000NM0055_upd_list |awk '{print $4}'`
	upd_fw_ali=`sed -n 2p ST8000NM0055_upd_list |awk '{print $4}'`
	if [[ "${Model}" =~ "${match_model}" ]];then
		if [[ "${FW_Ver}" =~ "SN0" ]] && [[ "${FW_Ver}" != "${match_fw_ver_common}" ]];then
			echo -e "\033[31m e${EID}:s${SID} start to upgrade ${Model} sata hdd common firmware \033[0m"
			/opt/MegaRAID/storcli/storcli64 /c$i/e${EID}/s${SID} download src=${upd_fw_common}
		elif [[ "${FW_Ver}" =~ "PN0" ]] && [[ "${FW_Ver}" != "${match_fw_ver_ali}" ]];then
			echo -e "\033[31m e${EID}:s${SID} start to upgrade ${Model} sata hdd ali firmware \033[0m"
                        /opt/MegaRAID/storcli/storcli64 /c$i/e${EID}/s${SID} download src=${upd_fw_ali}
		fi
	fi
	done
done
}

dell_megaraid_hdd_ST8000NM0055_upd(){
for i in `/opt/MegaRAID/perccli/perccli64 show all |grep -A 10 "Ctl Model" |grep -B 10 "Ctl=Controller Index" |sed -n '/^-/,/-$/p' |grep -v "^-" |awk '{print $1}' |sed '/^\s*$/d'`
do
        /opt/MegaRAID/perccli/perccli64 /c$i/eall/sall show |grep "HDD" |awk '{print $1,$(NF-2)}' > ${i}_dell_lsi_hdd_map
        for j in `seq 1 $(cat ${i}_dell_lsi_hdd_map |wc -l)`
        do
        Model=$(sed -n "$j"p ${i}_dell_lsi_hdd_map |awk '{print $2}')
        EID=$(sed -n "$j"p ${i}_dell_lsi_hdd_map |awk '{print $1}' |awk -F":" '{print $1}')
        SID=$(sed -n "$j"p ${i}_dell_lsi_hdd_map |awk '{print $1}' |awk -F":" '{print $2}')
        FW_Ver=$(/opt/MegaRAID/perccli/perccli64 /c$i/e${EID}/s${SID} show all  |grep "Firmware Revision" |awk '{print $NF}')
        match_model=`sed -n 1p ST8000NM0055_upd_list |awk '{print $2}'`
        match_fw_ver_common=`sed -n 1p ST8000NM0055_upd_list |awk '{print $3}'`
	match_fw_ver_ali=`sed -n 2p ST8000NM0055_upd_list |awk '{print $3}'`
        upd_fw_common=`sed -n 1p ST8000NM0055_upd_list |awk '{print $4}'`
	upd_fw_ali=`sed -n 2p ST8000NM0055_upd_list |awk '{print $4}'`
        if [[ "${Model}" =~ "${match_model}" ]];then
		if [[ "${FW_Ver}" =~ "SN0" ]] && [[ "${FW_Ver}" != "${match_fw_ver_common}" ]];then
                        echo -e "\033[31m e${EID}:s${SID} start to upgrade ${Model} sata hdd common firmware \033[0m"
                        /opt/MegaRAID/perccli/perccli64 /c$i/e${EID}/s${SID} download src=${upd_fw_common}
		elif [[ "${FW_Ver}" =~ "PN0" ]] && [[ "${FW_Ver}" != "${match_fw_ver_ali}" ]];then
                        echo -e "\033[31m e${EID}:s${SID} start to upgrade ${Model} sata hdd ali firmware \033[0m"
			/opt/MegaRAID/perccli/perccli64 /c$i/e${EID}/s${SID} download src=${upd_fw_ali}
                fi
        fi
        done
done
}

lsi_mptsas_hdd_ST8000NM0055_upd(){
which sg_write_buffer >/dev/null 2>&1
if [[ $? -ne 0 ]];then
	yum install sg3_utils -y
fi 
lsscsi -g |grep ATA > lsi_hba_hdd_map
for i in `awk '{print $NF}' lsi_hba_hdd_map`;do
	IS_HDD=`smartctl -i $i |grep "Rotation Rate" |awk -F":" '{print $NF}' |sed 's/^\s*//g'`
	Model=`smartctl -i $i |grep "Device Model" |awk -F":" '{print $NF}' |sed 's/\s*//g'`
	FW_Ver=`smartctl -i $i |grep "Firmware Version" |awk -F":" '{print $NF}' |sed 's/\s*//g'`
	if [[ "${IS_HDD}" =~ "rpm" ]];then
		match_model=`sed -n 1p ST8000NM0055_upd_list |awk '{print $2}'`
        	match_fw_ver_common=`sed -n 1p ST8000NM0055_upd_list |awk '{print $3}'`
		match_fw_ver_ali=`sed -n 2p ST8000NM0055_upd_list |awk '{print $3}'`
		upd_fw_common=`sed -n 1p ST8000NM0055_upd_list |awk '{print $4}'`
        	upd_fw_ali=`sed -n 2p ST8000NM0055_upd_list |awk '{print $4}'` 
		if [[ "${Model}" =~ "${match_model}" ]];then 
			if [[ "${FW_Ver}" != "SN05" ]];then
				echo -e "\033[31m $i ${Model} start to upgrade ${Model} sata hdd common firmware \033[0m"
				hdparm --fwdownload ${upd_fw_common} --yes-i-know-what-i-am-doing --please-destroy-my-drive $i
				if [[ $? -ne 0 ]];then
					continue
				fi
			elif [[ "${FW_Ver}" =~ "PN0" ]] && [[ "${FW_Ver}" != "${match_fw_ver_ali}" ]];then
                                echo -e "\033[31m $i ${Model} start to upgrade ${Model} sata hdd ali firmware \033[0m"
                                hdparm --fwdownload ${upd_fw_ali} --yes-i-know-what-i-am-doing --please-destroy-my-drive $i
                                if [[ $? -ne 0 ]];then
                                        continue
                                fi
			fi
		fi
	fi
done
}

pmc_aacraid_hdd_ST8000NM0055_upd(){
rm -rf *_pmc_vd_map pmc_aacraid_hdd_map_* *_os_disk_slot_map_*
for i in `arcconf list |grep "Controllers found" |awk '{print $NF}'`
do
	arcconf getconfig $i ld |grep "Logical Device number" |awk '{print $NF}' > ${i}_pmc_vd_map 
        for j in `grep -v "0" ${i}_pmc_vd_map`
        do
        arcconf delete $i logicaldrive $j noprompt >/dev/null 2>&1
        done
        controller_mode=`arcconf list $i |grep -Ew "Controller [0-9]*" |awk -F":" '{print $3}' |awk -F"," '{print $3}' |sed -e 's/(//' -e 's/)//' -e 's/\s*//g'`
        if [[ ${controller_mode} =~ "Hide RAW" ]];then
                arcconf setcontrollermode $i 0 >/dev/null 2>&1
                if [[ $? -ne 0 ]];then
                        echo "Please check the fucking PMC card and driver if any issue"
                        exit 1
                fi
        fi
done
sleep 5
#filter os ssd channel id and device id, then update firmware using arcconf tool
for controller_id in `arcconf list |grep "Controllers found" |awk '{print $NF}'`
do	
	HC=$((${controller_id}-1))
        arcconf list ${controller_id } |grep -A 100 "Physical ID" |grep "Hard Drive" > pmc_aacraid_hdd_map_${controller_id}
	for i in `seq 1 $(cat pmc_aacraid_all_map |wc -l)`
	do
        	Channel_ID=$(sed -n "$i"p pmc_aacraid_all_map_${controller_id} |awk '{print $1}' |awk -F"(" '{print $1}' |awk -F"," '{print $1}')
        	Device_ID=$(sed -n "$i"p pmc_aacraid_all_map_${controller_id} |awk '{print $1}' |awk -F"(" '{print $1}' |awk -F"," '{print $2}')
        	Disk_SN=`smartctl -i -d aacraid,$HC,${Channel_ID},${Device_ID} /dev/sda |awk '/Serial Number/{print $NF}' |sed 's/\s*//g'`
        	for os_sn in `arcconf getconfig 1 ld 0  |grep -E "Segment|Present" |awk '{print $NF}' |sed 's/\s*//g'`
        	do
                	if [[ ${Disk_SN} == ${os_sn} ]];then
                        	echo -e "${Channel_ID},${Device_ID}" >> os_disk_slot_map_${controller_id}
                	fi
        	done
	done
	cat os_disk_slot_map_${controller_id} |sort -u > real_os_disk_slot_map_${controller_id}
	for j in `seq 1 $(cat real_os_disk_slot_map_${controller_id})`
	do
		New_Channel_ID=$(sed -n "$j"p real_os_disk_slot_map_${controller_id} |awk -F"," '{print $1}')
		New_Device_ID=$(sed -n "$j"p real_os_disk_slot_map_${controller_id} |awk -F"," '{print $2')
		Model=$(smartctl -i -d aacraid,$HC,${New_Channel_ID},${New_Device_ID} /dev/sda |grep "Device Model" |awk '{print $NF}')
		FW_Ver=$(smartctl -i -d aacraid,$HC,${New_Channel_ID},${New_Device_ID} /dev/sda |grep "Firmware Version" |awk '{print $NF}')
                match_model=`sed -n 1p ST8000NM0055_upd_list |awk '{print $2}'`
                match_fw_ver_common=`sed -n 1p ST8000NM0055_upd_list |awk '{print $3}'`
		match_fw_ver_ali=`sed -n 2p ST8000NM0055_upd_list |awk '{print $3}'`
                upd_fw_common=`sed -n 1p ST8000NM0055_upd_list |awk '{print $4}'`
		upd_fw_ali=`sed -n 2p ST8000NM0055_upd_list |awk '{print $4}'`
		if [[ "${Model}" =~ "${match_model}" ]];then
			if [[ "${FW_Ver}" =~ "SN0" ]] && [[ "${FW_Ver}" != "${match_fw_ver_common}" ]];then
				echo -e "\033[31m ${New_Channel_ID},${New_Device_ID} start to upgrade ${Model} sata hdd common firmware \033[0m"
				arcconf imageupdate ${controller_id} device ${New_Channel_ID} ${New_Device_ID} 32768 ${upd_fw_common} noprompt
			elif [[ "${FW_Ver}" =~ "PN0" ]] && [[ "${FW_Ver}" != "${match_fw_ver_ali}" ]];then
                                echo -e "\033[31m ${New_Channel_ID},${New_Device_ID} start to upgrade ${Model} sata hdd ali firmware \033[0m"
                                arcconf imageupdate ${controller_id} device ${New_Channel_ID} ${New_Device_ID} 32768 ${upd_fw_ali} noprompt
			fi
		fi
	done
done
#Update data ssd firmware using hdparm tool that can make them take effect immediately
lsscsi -g |grep ATA > pmc_data_disk_map
for k in `awk '{print $NF}' pmc_data_disk_map`
do
        IS_HDD=`smartctl -i $k |grep "Rotation Rate" |awk -F":" '{print $NF}' |sed 's/^\s*//g'`
        Model=`smartctl -i $k |grep "Device Model" |awk -F":" '{print $NF}' |sed 's/\s*//g'`
        FW_Ver=`smartctl -i $k |grep "Firmware Version" |awk -F":" '{print $NF}' |sed 's/\s*//g'`
        match_model=`sed -n 1p ST8000NM0055_upd_list |awk '{print $2}'`
        match_fw_ver_common=`sed -n 1p ST8000NM005_upd_list |awk '{print $3}'`
	match_fw_ver_ali=`sed -n 2p ST8000NM0055_upd_list |awk '{print $3}'`
        upd_fw_common=`sed -n 1p ST8000NM0055_upd_list |awk '{print $4}'`
	upd_fw_ali=`sed -n 2p ST8000NM0055_upd_list |awk '{print $4}'`
        if [[ "${IS_HDD}" =~ "rpm" ]];then
        	if [[ "${Model}" =~ "${match_model}" ]];then
			if [[ "${FW_Ver}" =~ "SN0" ]] && [[ "${FW_Ver}" != "${match_fw_ver_common}" ]];then
                		echo -e "\033[31m $k start to update ${Model} sata hdd common firmware\033[0m"
                        	hdparm --fwdownload ${upd_fw_common} --yes-i-know-what-i-am-doing --please-destroy-my-drive $k
                        	if [[ $? -ne 0 ]];then
                                	continue
                                fi
                                sleep 10
			elif [[ "${FW_Ver}" =~ "PN0" ]] && [[ "${FW_Ver}" != "${match_fw_ver_ali}" ]];then
                                echo -e "\033[31m $k start to update ${Model} sata hdd ali firmware\033[0m"
                                hdparm --fwdownload ${upd_fw_ali} --yes-i-know-what-i-am-doing --please-destroy-my-drive $k
                                if [[ $? -ne 0 ]];then
                                        continue
                                fi
                                sleep 10
			fi
                fi
        fi
done
}

pmc_smartpqi_hdd_ST8000NM0055_upd(){
rm -rf pmc_smartpqi_all_map os_disk_slot_map real_os_disk_slot_map 
for i in `arcconf list |grep "Controllers found" |awk '{print $NF}'`
do
        arcconf getconfig $i ld |grep "Logical Device number" |awk '{print $NF}' > ${i}_pmc_vd_map
        for j in `grep -v "0" ${i}_pmc_vd_map`
        do
        arcconf delete $i logicaldrive $j noprompt >/dev/null 2>&1
        done
        controller_mode=`arcconf list $i |grep -Ew "Controller [0-9]*" |awk -F":" '{print $3}' |awk -F"," '{print $3}' |sed 's/\s*//g'`
        if [[ ${controller_mode} != "Mixed" ]];then
                arcconf setcontrollermode $i 5 >/dev/null 2>&1
                if [[ $? -ne 0 ]];then
                        echo "Please check the fucking PMC card and driver if any issue"
                        exit 1
                fi
        fi
done
sleep 5

# Find the os ssd channel and device id arccording to SN 
for controller_id in `arcconf list |grep "Controllers found" |awk '{print $NF}'`
do
        arcconf getconfig ${controller_id} pd |grep -A10 "Device is a Hard drive" |grep -E "Reported Channel,Device|Model" |awk '{print $NF}' |sed 'N;s/\n/ /' >> pmc_smartpqi_all_map
done
for i in $(seq 0 `expr $(cat pmc_smartpqi_all_map |wc -l) - 1`)
do
        Channel_ID=$(sed -n "$(($i+1))"p pmc_smartpqi_all_map |awk '{print $1}' |awk -F"(" '{print $1}' |awk -F"," '{print $1}')
        Device_ID=$(sed -n "$(($i+1))"p pmc_smartpqi_all_map |awk '{print $1}' |awk -F"(" '{print $1}' |awk -F"," '{print $2}')
        Disk_SN=`smartctl -i -d cciss,$i /dev/sda |awk '/Serial Number/{print $NF}' |sed 's/\s*//g'`
        for os_sn in `arcconf getconfig 1 ld 0  |grep -E "Segment|Present" |awk '{print $NF}' |sed 's/\s*//g'`
        do
                if [[ ${Disk_SN} == ${os_sn} ]];then
                        echo -e "${Channel_ID},${Device_ID},$i" >> os_disk_slot_map
                fi
        done
done
sort -u os_disk_slot_map > real_os_disk_slot_map
# Update os ssd firmware using arcconf tool
if [ -s real_os_disk_slot_map ];then
        for controller_id in `arcconf list |grep "Controllers found" |awk '{print $NF}'`
        do
                for j in `seq 1 $(cat real_os_disk_slot_map |wc -l)`
                do
                        cciss_id=$(sed -n "$j"p real_os_disk_slot_map |awk -F"," '{print $3}')
                        IS_HDD=`smartctl -i -d cciss,${cciss_id} /dev/sda |grep "Rotation Rate" |awk -F":" '{print $NF}' |sed 's/^\s*//g'`
                        Model=`smartctl -i -d cciss,${cciss_id} /dev/sda |grep "Device Model" |awk -F":" '{print $NF}' |sed 's/\s*//g'`
                        FW_Ver=`smartctl -i -d cciss,${cciss_id} /dev/sda |grep "Firmware Version" |awk -F":" '{print $NF}' |sed 's/\s*//g'`
                        New_Channel_ID=$(sed -n "$j"p real_os_disk_slot_map |awk -F"," '{print $1}')
                        New_Device_ID=$(sed -n "$j"p real_os_disk_slot_map |awk -F"," '{print $2}')
                        match_model=`sed -n 1p ST8000NM0055_upd_list |awk '{print $2}'`
                        match_fw_ver_common=`sed -n 1p ST8000NM0055_upd_list |awk '{print $3}'`
			match_fw_ver_common=`sed -n 2p ST8000NM0055_upd_list |awk '{print $3}'`
			upd_fw_ali=`sed -n 1p ST8000NM0055_upd_list |awk '{print $4}'`
                        upd_fw_ali=`sed -n 2p ST8000NM0055_upd_list |awk '{print $4}'`
                                if [[ "${IS_HDD}" =~ "rpm" ]];then
                                        if [[ "${Model}" =~ "${match_model}" ]];then
						if [[ "${FW_Ver}" =~ "SN0" ]] && [[ "${FW_Ver}" != "${match_fw_ver_common}" ]];then
                                                	echo -e "\033[31m ${New_Channel_ID},${New_Device_ID} start to update ${Model} sata hdd common firmware \033[0m"
                                                	#H3C arcconf tool to update ssd connected in PMC smartpqi RAID/HBA card
                                                	arcconf imageupdate ${controller_id} device ${New_Channel_ID} ${New_Device_ID} 32768 ${upd_fw_common} noprompt
                                                	if [[ $? -ne 0 ]];then
                                                        	continue
                                                	fi
						elif [[ "${FW_Ver}" =~ "PN0" ]] && [[ "${FW_Ver}" != "${match_fw_ver_ali}" ]];then
                                                        echo -e "\033[31m ${New_Channel_ID},${New_Device_ID} start to update ${Model} sata hdd ali firmware \033[0m"
                                                        #H3C arcconf tool to update ssd connected in PMC smartpqi RAID/HBA card
                                                        arcconf imageupdate ${controller_id} device ${New_Channel_ID} ${New_Device_ID} 32768 ${upd_fw_ali} noprompt
                                                        if [[ $? -ne 0 ]];then
                                                                continue
                                                        fi
						fi
                                                sleep 10
                                        fi
                                fi
                done
        done
fi

#Update data ssd firmware using hadprm that can make ssd firmware take effect immediately
lsscsi -g |grep ATA > pmc_data_disk_map
for k in `awk '{print $NF}' pmc_data_disk_map`
do
        IS_HDD=`smartctl -i $k |grep "Rotation Rate" |awk -F":" '{print $NF}' |sed 's/^\s*//g'`
        Model=`smartctl -i $k |grep "Device Model" |awk -F":" '{print $NF}' |sed 's/\s*//g'`
        FW_Ver=`smartctl -i $k |grep "Firmware Version" |awk -F":" '{print $NF}' |sed 's/\s*//g'`
        match_model=`sed -n 1p ST8000NM0055_upd_list |awk '{print $2}'`
        match_fw_ver_common=`sed -n 1p ST8000NM0055_upd_list |awk '{print $3}'`
	match_fw_ver_ali=`sed -n 2p ST8000NM0055_upd_list |awk '{print $3}'`
        upd_fw_common=`sed -n 1p ST8000NM0055_upd_list |awk '{print $4}'`
	upd_fw_ali=`sed -n 2p ST8000NM0055_upd_list |awk '{print $4}'`
                if [[ "${IS_HDD}" =~ "rpm" ]];then
                        if [[ "${Model}" =~ "${match_model}" ]];then
				if [[ "${FW_Ver}" =~ "SN0" ]] && [[ "${FW_Ver}" != "${match_fw_ver_common}" ]];then
                                	echo -e "\033[31m $k start to update ${Model} sata hdd common firmware \033[0m"
                                	hdparm --fwdownload ${upd_fw_common} --yes-i-know-what-i-am-doing --please-destroy-my-drive $k
                                	if [[ $? -ne 0 ]];then
                                        	continue
                                	fi
                                	sleep 10
				 elif [[ "${FW_Ver}" =~ "PN0" ]] && [[ "${FW_Ver}" != "${match_fw_ver_ali}" ]];then
                                        echo -e "\033[31m $k start to update ${Model} sata hdd ali common \033[0m"
                                        hdparm --fwdownload ${upd_fw_ali} --yes-i-know-what-i-am-doing --please-destroy-my-drive $k
                                        if [[ $? -ne 0 ]];then
                                                continue
                                        fi
                                        sleep 10
                        	fi
                	fi
		fi
done
}

direct_hdd_ST8000NM0055_upd(){
lsscsi -g |grep ATA > direct_ssd_map
for i in `cat direct_ssd_map`;do
        IS_HDD=`smartctl -i $i |grep "Rotation Rate" |awk -F":" '{print $NF}' |sed 's/^\s*//g'`
        Model=`smartctl -i $i |grep "Device Model" |awk -F":" '{print $NF}' |sed 's/\s*//g'`
        FW_Ver=`smartctl -i $i |grep "Firmware Version" |awk -F":" '{print $NF}' |sed 's/\s*//g'`
	match_model=`sed -n 1p ssd_upd_list |awk '{print $2}'`
        match_fw_ver_common=`sed -n 1p ssd_upd_list |awk '{print $3}'`
	match_fw_ver_common=`sed -n 1p ssd_upd_list |awk '{print $3}'`
        upd_fw_common=`sed -n 1p ssd_upd_list |awk '{print $4}'`
	upd_fw_ali=`sed -n 2p ssd_upd_list |awk '{print $4}'`
	if [[ "${IS_HDD}" =~ "rpm" ]];then
        	if [[ "${Model}" =~ "${match_model}" ]];then
			if [[ "${FW_Ver}" =~ "SN0" ]] && [[ "${FW_Ver}" != "${match_fw_ver_common}" ]];then
	                        echo -e "\033[31m $i start to upgrade ${Model} sata hdd common firmware \033[0m"
                        	hdparm --fwdownload ${upd_fw_common} --yes-i-know-what-i-am-doing --please-destroy-my-drive $i
                        	if [[ $? -ne 0 ]];then
                                	continue
                        	fi
				sleep 10
			elif [[ "${FW_Ver}" =~ "PN0" ]] && [[ "${FW_Ver}" != "${match_fw_ver_ali}" ]];then
                        	echo -e "\033[31m $i start to upgrade ${Model} sata hdd ali firmware \033[0m"
                                hdparm --fwdownload ${upd_fw_ali} --yes-i-know-what-i-am-doing --please-destroy-my-drive $i
                                if [[ $? -ne 0 ]];then
                                        continue
                                fi
			fi
		fi 
        fi
done
}


#os_version=`uname -r |awk -F"el" '{print $2}' |awk -F"." '{print $1}'`
which hdparm >/dev/null 2>&1
if [ $? -ne 0 ];then
	yum install -y hdparm
else
	if [[ $(hdparm -V |awk '{print $2}') != "v9.58" ]];then
		yum update -y hdparm
	fi
fi
lspci |grep -Ei "lsi|broadcom|pmc|adaptec" |grep -i sas > bdm_pmc_map
if [ -s bdm_pmc_map ];then
	for i in `seq 1 $(cat bdm_pmc_map |wc -l)`
	do
	bus_id=`sed -n "$i"p bdm_pmc_map |awk '{print $1}'`
	sas_description=`echo $(sed -n "$i"p bdm_pmc_map) |tr 'A-Z' 'a-z'`
	if [[ ${sas_description} =~ "adpatec" ]];then
		if [[ "$(arcconf  |grep Version |awk '{print $5}')" !=  "3.07.00" ]];then
                        rpm -Uvh Arcconf-3.07-23971.x86_64.rpm
			echo y |mv /usr/Arcconf/arcconf /usr/sbin/arcconf
                fi
	fi
	driver_type=`lspci -i pci.ids -s ${bus_id} -v |grep "Kernel driver in use" |awk '{print $NF}' |sed 's/\s*//'`
	if [[ "${driver_type}" = "megaraid_sas" ]];then
		Manufacturer=$(dmidecode -s system-manufacturer |tr 'A-Z' 'a-z')
		if [[ "${Manufacturer}" =~ "dell" ]];then
			dell_megaraid_hdd_ST8000NM0055_upd
		else 
			lsi_megaraid_hdd_ST8000NM0055_upd
		fi
	elif [[ "${driver_type}" = "mpt2sas" ]] || [[ "${driver_type}" = "mpt3sas" ]];then
			lsi_mptsas_hdd_ST8000NM0055_upd
	elif [[ "${driver_type}" = "aacraid" ]];then 
			pmc_aacraid_hdd_ST8000NM0055_upd
	elif [[ "${driver_type}" = "smartpqi" ]];then
			pmc_smartpqi_hdd_ST8000NM0055_upd
	fi
	done
else
		direct_hdd_ST8000NM0055_upd
fi	
