#!/bin/sh

# Install QLSDM library. Check /etc/hba.conf

echo "Setting up QLogic HBA API library..."

APIDIR=ApiPkg

mkdir -p ${APIDIR}
cd ${APIDIR}

tar xfz ../qlapi*rel.tgz

cp --suffix=.bak --backup=simple ./lib/libqlsdm.so /usr/lib

if [ -s /etc/hba.conf ]
then

    if [ -r /etc/hba.conf ] && [ -w /etc/hba.conf ]
    then
        grep -v qla2x00 /etc/hba.conf > ./tmp.conf

        if [ -s ./tmp.conf ]
        then
            rm -f /etc/hba.conf.bak
            mv /etc/hba.conf /etc/hba.conf.bak
            sed '$r ./hba.conf' ./tmp.conf > /etc/hba.conf
        fi

        rm ./tmp.conf
    else
        echo "Permission denied."
        exit
    fi

else
    cp ./hba.conf /etc
fi

echo "Done."

