#!/bin/bash
 
MODULES="pci_slot"

F=/etc/redflag-release
[ ! -f $F ] && F=/etc/redhat-release
[ ! -f $F ] && F=/etc/SuSE-release
[ ! -f $F ] && echo "Can't find xxxx-release file" >&2 && exit 1

R=`rpm -qf $F --queryformat='%{VERSION}'`
[ -z "$R" ] && echo "Can't get Distro Version for $F" >&2 && exit 1

# For RHEL6 & RHEL7, the kernel has pci_slot built into it, there is no needs to auto loading
[ "$F" == "/etc/redhat-release" -a "${R:0:1}" -ge 6 ] && exit 0
# For SUSE12 Server, the kernel has pci_slot built into it, there is no needs to auto loading
[ "$F" == "/etc/SuSE-release" -a "${R:0:2}" -ge 12 ] && exit 0


for MOD_NAME in $MODULES; do
  if [ "$1" = start ]; then
    if [ -z "$(lsmod | grep $MOD_NAME)" ];  then
        modprobe $MOD_NAME
        [ $? -ne 0 ] && echo "modprobe $MOD_NAME failed" >&2 && exit 1
    fi
  fi
done
exit 0

