#!/bin/sh -e


##########################################################################
#   Function description:
#       Pause until user presses return
##########################################################################

pause()
{
    local junk
    
    printf "Press return to continue..."
    read junk
}

cd /usr/src/sys/$(uname -p)/conf
if [ ! -e IB ]; then
    cp GENERIC IB
fi

if ! fgrep -q OFED IB; then
    cat << EOM >> IB

# IPOIB is causes severe performance probelms.  Mellanox is rewriting
# the driver as of Mar 2014 with expected ETA summer 2014.

options        OFED            # Infiniband protocol stack and support
options        SDP             # Sockets Direct Protocol for infiniband
options        IPOIB_CM        # Use connect mode ipoib

device         ipoib           # IP over IB devices
device         mlx4ib          # ConnectX Infiniband support
device         mlxen           # ConnectX Ethernet support
device         mthca           # Infinihost cards

EOM
fi

# Build IB support into userland tools (e.g. ifconfig)
freebsd-ib-buildworld

# Build kernel
cd /usr/src
if [ ! -e kernel-built ]; then
    make buildkernel KERNCONF=IB
    make installkernel KERNCONF=IB
    touch kernel-built
fi

cat << EOM

Rebooting to single user mode.  Run freebsd-ib-setup-single-user.

EOM

pause
nextboot -o "-s" -k kernel
shutdown -r now

