#!/bin/sh
#
# momonga	This shell script is for Momonga Linux Support.
#
#
# Author:	Makoto Kikutani <g@kondara.org>
#			Tenkou N. Hattori <tnh@kondara.org>
#			Dyky Matsuda <dyky@kondara.org>
#
# chkconfig:  345 90 90
# description: Momonga Linux Support
#

[ "$1" != "start" ] && exit 0

echo -n "relinking some header files"

curker=`uname -r`
case $curker in
  *own) suffix="own" ;;
  *dp264) suffix="dp264" ;;
  *dp264-smp) suffix="dp264-smp" ;;
  *nautilus) suffix="nautilus" ;;
  *wildfire) suffix="wildfire" ;;
  *cm) suffix="cm" ;;
  *cm-smp) suffix="cm-smp" ;;
  *p4) suffix="p4" ;;
  *p4-smp) suffix="p4-smp" ;;
  *icc) suffix="icc" ;;
  *icc-smp) suffix="icc-smp" ;;
  *k7) suffix="k7" ;;
  *k7-smp) suffix="k7-smp" ;;
  *fiva) suffix="fiva" ;;
  *smp) suffix="smp" ;;
  *um) suffix="dummy" ;;
  *) suffix="uni" ;;
esac

name=`basename $curker $suffix`
minor=`uname -r | awk -F '.' '{print $2}'`
if [ -d /usr/src ]; then
  cd /usr/src
  for h in linux;  do
    for hh in $h $h-2.$minor; do
      if [ ! -e $hh -o -L $hh ]; then
        /bin/rm -f $hh
        ln -sf $h-$name /usr/src/$hh
      fi
    done
    if [ $suffix = "own" ] ; then
      exit;
    fi
  done
fi
if [ -d /usr/include/linux ]; then
  cd /usr/include/linux
  for h in modules;  do
    if [ ! -e $h -o -L $h ]; then
      rm -f $h
      ln -sf ${h}-${suffix} /usr/include/linux/${h}
    fi
  done
  if [ $minor == "4" ]; then
    for h in autoconf modversions version;  do
      if [ ! -e ${h}.h -o -L ${h}.h ]; then
        /bin/rm -f ${h}.h
        ln -sf ${h}-${suffix}.h /usr/include/linux/${h}.h
      fi
    done
  else
    for h in autoconf compile version;  do
      if [ ! -e ${h}.h -o -L ${h}.h ]; then
        /bin/rm -f ${h}.h
        ln -sf ${h}-${suffix}.h /usr/include/linux/${h}.h
      fi
    done
  fi
fi

if [ -f /etc/sysconfig/firsttime/RUN_FIRSTTIME ] ; then
  pushd /etc/sysconfig/firsttime > /dev/null
  for i in *
  do
    case $i in
      RUN_FIRSTTIME) ;;
      *) sh $i;;
    esac
  done
  popd > /dev/null
fi
rm -f /etc/sysconfig/firsttime/RUN_FIRSTTIME
