#!/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_hal rtai_ksched rtai_math rtai_fifos rtai_shm rtai_sem ; do
    /sbin/modprobe $module || exit 1
  done
  /sbin/insmod shm_task.o
  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 rtai_sched rtai_libm rtai_fifos rtai_shm ; do
    /sbin/modprobe $module || exit 1
  done
  /sbin/insmod shm_task.o
  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 1
  for module in rtai rtai_sched rtai_fifos rtai_shm ; do
    /sbin/modprobe $module || exit 1
  done
  /sbin/insmod shm_task.o
  exit 0
fi

# else no RTAI
exit 1
