#!/bin/bash

STORCLI_TOOL="storcli-007.2807.0000.0000-1.noarch.rpm"
RAID_ROM="52.28.0-5305_9540-8i.rom"
STORCLI_BIN="/opt/MegaRAID/storcli/storcli64"

if ! rpm -q storcli &> /dev/null; then
    echo "Installing storcli..."
    rpm -ivh "$STORCLI_TOOL" || { echo "Failed to install storcli."; exit 1; }
else
    echo "storcli is already installed."
fi

# 执行 RAID 固件升级
echo "Upgrading RAID controller firmware..."
command="$STORCLI_BIN /c0 download file=\"$RAID_ROM\" resetnow noverchk"
output=$($command 2>&1)
if [ $? -eq 0 ]; then
    echo "RAID controller firmware upgrade successful."
    echo "$output"
else
    echo "RAID controller firmware upgrade failed."
    echo "$output"
    exit 1
fi
