#!/bin/bash

PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin

if which uspepc >/dev/null 2>&1; then
    USPEPC=uspepc
else
    USPEPC=/bin/false
fi

if which cgutlcmd >/dev/null 2>&1; then
    CGUTLCMD=cgutlcmd
else
    CGUTLCMD=/bin/false
fi

wdstop

if [ -f /tmp/watchdog ] ; then
    rm /tmp/watchdog
fi

# Special for HP server                                                                                                                                                                        
if dmidecode | grep -q "Vendor: HP"; then
    if dmidecode | grep -q 'Product Name: ProLiant .* G7'; then
        rmmod iTCO_wdt >/dev/null 2>&1  # Remove because this doesn't work
        rmmod iTCO_vendor_support >/dev/null 2>&1
        modprobe hpwdt soft_margin=300 nowayout=0

    elif dmidecode | grep -q "Product Name: ProLiant DL380p Gen8"; then
        rmmod iTCO_wdt >/dev/null 2>&1
        rmmod iTCO_vendor_support >/dev/null 2>&1
        modprobe hpwdt soft_margin=300 nowayout=0

    else
        rmmod hpwdt >/dev/null 2>&1
        modprobe iTCO_wdt heartbeat=300 nowayout=0
    fi
    wdstart.hp
    
    # MSC
elif ${USPEPC} -INFO -b 2>/dev/null| head -1 | grep -q "HW platform:.*Q7-US15W";then
    if [ -f /dev/watchdog ] ; then
        rm /dev/watchdog
    fi
    wdstart.msc
    wds.msc &

    # Congatec    
elif ${CGUTLCMD} cginfo /ot:board /dump /cgos 2>/dev/null >/dev/null ;then     
    if [ -f /dev/watchdog ] ; then
        rm /dev/watchdog
    fi
    wdstart.cgt
    wds.cgt &
fi

/usr/bin/wdhole &
