#!/bin/sh -e

##########################################################################
#   Script description:
#       auto-update-infiniband-modules
#       Rebuild and reload infiniband modules after a src tree update
#       
#   History:
#   Date        Name        Modification
#   2019-04-14  Charlie &   Begin
##########################################################################

usage()
{
    printf "Usage: $0 datagram|connected\n"
    exit 1
}


##########################################################################
#   Main
##########################################################################

if [ $# != 1 ]; then
    usage
fi
    
case $(auto-ostype) in
FreeBSD)
    auto-install-infiniband-modules $1
    for interface in $(ifconfig | awk -F : '$1 ~ "^ib" { print $1 }'); do
	ifconfig $interface down
    done
    
    kldunload ipoib mlx4ib ibcore mlx4
    sleep 2
    kldload mlx4 ibcore mlx4ib ipoib
    
    for interface in $(ifconfig | awk -F : '$1 ~ "^ib" { print $1 }'); do
	ifconfig $interface up
    done
    ;;
    
*)
    auto-unsupported-os $0
    exit 1
    ;;

esac
