#!/bin/sh

# Test for RTAI 3, using heuristic that there will be a module in
# the booted kernel's /lib/modules/XXX/rtai/ directory named 'rtai_hal.o'

if [ -f /lib/modules/`uname -r`/rtai/rtai_hal.o ] ; then
# have RTAI 3
  for module in rtai_sem rtai_shm rtai_fifos rtai_ksched rtai_hal ;  do
    /sbin/rmmod $module 2> /dev/null
  done
  /sbin/rmmod fifo_task
  exit 0
fi

# Test for RTAI 2, using heuristic that there will be a module in
# the booted kernel's /lib/modules/XXX/rtai/ directory named 'rtai.o'

if [ -f /lib/modules/`uname -r`/rtai/rtai.o ] ; then
# have RTAI 2
  for module in rtai_shm rtai_fifos rtai_sched rtai ; do
    /sbin/rmmod $module 2> /dev/null
  done
  /sbin/rmmod fifo_task
  exit 0
fi

# Test for RTAI 1, using heuristic that there will be a module in
# the booted kernel's /lib/modules/XXX/misc/ directory named 'rtai.o'

if [ -f /lib/modules/`uname -r`/misc/rtai.o ] ; then
# have RTAI 2
  for module in rtai_shm rtai_fifos rtai_sched rtai ; do
    /sbin/rmmod $module 2> /dev/null
  done
  /sbin/rmmod fifo_task
  exit 0
fi

# else no RTAI
exit 1

