#!/bin/bash
# must be executable otherwise it won't work on debian

set -u

if [ "$1" = start ]; then
    $OPTTOP/OpenIPMI/load_modules
    if [ $? -ne 0 ]; then
	FAILMSG="Could not load Open IPMI modules\n\nSee the README in $OPTTOP/OpenIPMI"
    else
	DEV=`grep 'ipmidev$' /proc/devices | awk '{print $1}'`
	if [ -z "$DEV" ]; then
	    FAILMSG="IPMI device major number not found"
	else # build a new dev file in case modules were reloaded
	    rm -f /dev/ipmi0 /dev/ipmidev/0
	    mknod -m 600 /dev/ipmi0 c $DEV 0
	    mkdir -p /dev/ipmidev 2>/dev/null
	    mknod -m 600 /dev/ipmidev/0 c $DEV 0

	    # hpbmc SetOANameStrings 2>/dev/null now in S04hpipmid

	fi
    fi
fi

exit 0
