#!/bin/sh

#**********************************************************************************
# Copyright (c) 1999-2000, Intel Corporation 
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without 
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, 
# this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation 
# and/or other materials provided with the distribution.
#
# 3. Neither the name of Intel Corporation nor the names of its contributors 
# may be used to endorse or promote products derived from this software 
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 
# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
# EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
#
#***********************************************************************************

KERNVER=`cat /proc/version | awk "{print \\$3}"`
echo running kernel $KERNVER

if [ ${BUILD_ROOT} ]
then
      KERNELVER=`cat ${KERNEL_SOURCE}/include/linux/version.h |grep UTS_RELEASE | awk ' { print $3 } ' | awk -F\" ' { print $2 } '`
      CharModDir=${BUILD_ROOT}/lib/modules/${KERNVER}/kernel/drivers/char
      echo Target kernel version is $KERNELVER
else
case $KERNVER in
   2.4*)
      CharModDir=/lib/modules/${KERNVER}/kernel/drivers/char
      ;;
   2.6*)
      CharModDir=/lib/modules/${KERNVER}/kernel/drivers/char
      ;;
   *)
      echo "unsupported kernel version. 2.4.x is supported. 2.6.x support is experimental yet"
      exit 1
      ;;
esac
fi


chmod 755 hamregistry usrsound

if [ -a /etc/mandrake-release ]; then
{
   if [ -a ./hamregistry.bin ]; then
   {
      mv -f /etc/hamregistry.bin /etc/hamregistry.bak
      cp ./hamregistry.bin /etc/hamregistry.bin
   }
   else
   {
      rm -f /etc/hamregistry.bin
   }
   fi
   echo installing hamregistry, used for persistant storage
   install -o root -g root -m 110 hamregistry /usr/sbin
   echo installing usrsound, a soft buzzer
   install -o root -g root -m 755 usrsound /usr/sbin
   echo installing ham module
   install -o root -g root -m 664 Intel537.o ${CharModDir}/Intel537.o || exit 1

   echo mandrake 537_boot script
   install -o root -g root -m 110 537_boot /etc/rc.d/init.d || exit 1

   ln -s -f /etc/rc.d/init.d/537_boot /etc/rc.d/rc2.d/S99537_boot
   ln -s -f /etc/rc.d/init.d/537_boot /etc/rc.d/rc3.d/S99537_boot
   ln -s -f /etc/rc.d/init.d/537_boot /etc/rc.d/rc5.d/S99537_boot
}
elif [ -a /etc/SuSE-release ]; then
{
   if [ -a ./hamregistry.bin ]; then
   {
      mv -f /etc/hamregistry.bin /etc/hamregistry.bak
      cp ./hamregistry.bin /etc/hamregistry.bin
   }
   else
   {
      rm -f /etc/hamregistry.bin
   }
   fi
   echo installing hamregistry, used for persistant storage
   install -o root -g root -m 110 hamregistry /usr/sbin || exit 1
   echo installing usrsound, a soft buzzer
   install -o root -g root -m 755 usrsound /usr/sbin
   echo installing 537 module
   install -o root -g root -m 664 Intel537.o ${CharModDir}/Intel537.o || exit 1

   DISTVER=`grep VERSION /etc/SuSE-release | cut -f3 -d' '`
   echo SuSE version ${DISTVER}
   case $DISTVER in
      6*|7.0)
         echo "SuSE <= 7.0 boot scripts"
         INITDIR='/sbin/init.d'
         ;;
      5* | 4* | 3* | 2* | 1*)
         echo "unsupported SuSE version. no boot scripts installed"
         exit 1
         ;;
      *)
         echo "SuSE boot scripts"
         INITDIR='/etc/init.d'
         ;;
   esac
   install -o root -g root -m 110 537_boot $INITDIR || exit 1
   ln -s -f ${INITDIR}/537_boot ${INITDIR}/boot.d/S99537_boot

}
elif [ -a /etc/redhat-release ]; then
{
   if [ -a ./hamregistry.bin ]; then
   {
      mv -f ${BUILD_ROOT}/etc/hamregistry.bin ${BUILD_ROOT}/etc/hamregistry.bak
      cp ./hamregistry.bin ${BUILD_ROOT}/etc/hamregistry.bin
   }
   else
   {
      rm -f /etc/hamregistry.bin
   }
   fi
   echo installing hamregistry, used for persistant storage
   install -o root -g root -m 110 hamregistry ${BUILD_ROOT}/usr/sbin
   echo installing usrsound, a soft buzzer
   install -o root -g root -m 755 usrsound ${BUILD_ROOT}/usr/sbin
   echo installing 537 module
   install -o root -g root -m 664 Intel537.o ${CharModDir}/Intel537.o || exit 1

   echo redhat 537_boot rc2.d, rc3.d and rc5.d scripts
   install -o root -g root -m 110 537_boot ${BUILD_ROOT}/etc/rc.d/init.d || exit 1
   ln -s -f ${BUILD_ROOT}/etc/rc.d/init.d/537_boot ${BUILD_ROOT}/etc/rc.d/rc2.d/S99537_boot
   ln -s -f ${BUILD_ROOT}/etc/rc.d/init.d/537_boot ${BUILD_ROOT}/etc/rc.d/rc3.d/S99537_boot
   ln -s -f ${BUILD_ROOT}/etc/rc.d/init.d/537_boot ${BUILD_ROOT}/etc/rc.d/rc5.d/S99537_boot
}
elif [ -a /etc/redflag-release ]; then
{
   if [ -a ./hamregistry.bin ]; then
   {
      mv -f /etc/hamregistry.bin /etc/hamregistry.bak
      cp ./hamregistry.bin /etc/hamregistry.bin
   }
   else
   {
      rm -f /etc/hamregistry.bin
   }
   fi
   echo installing hamregistry, used for persistant storage
   install -o root -g root -m 110 hamregistry /usr/sbin
   echo installing usrsound, a soft buzzer
   install -o root -g root -m 755 usrsound /usr/sbin
   echo installing 537 module
   install -o root -g root -m 664 Intel537.o ${CharModDir}/Intel537.o

   echo redhat hamboot rc2.d and rc3.d scripts
   install -o root -g root -m 110 537-boot /etc/rc.d/init.d
   ln -s -f /etc/rc.d/init.d/537-boot /etc/rc.d/rc2.d/S99537-boot
   ln -s -f /etc/rc.d/init.d/537-boot /etc/rc.d/rc3.d/S99537-boot
   ln -s -f /etc/rc.d/init.d/537-boot /etc/rc.d/rc5.d/S99537-boot
}
elif [ -a /etc/conectiva-release ]; then
{
   if [ -a ./hamregistry.bin ]; then
   {
      mv -f /etc/hamregistry.bin /etc/hamregistry.bak
      cp ./hamregistry.bin /etc/hamregistry.bin
   }
   else
   {
      rm -f /etc/hamregistry.bin
   }
   fi
   echo installing hamregistry, used for persistant storage
   install -o root -g root -m 110 hamregistry /usr/sbin
   echo installing usrsound, a soft buzzer
   install -o root -g root -m 755 usrsound /usr/sbin
   echo installing 537 module
   install -o root -g root -m 664 Intel537.o ${CharModDir}/Intel537.o || exit 1

   echo conectiva 537_boot rc3.d and rc5.d scripts
   install -o root -g root -m 755 537_boot /etc/rc.d/init.d
   ln -s -f /etc/rc.d/init.d/537_boot /etc/rc.d/rc3.d/S99537_boot
   ln -s -f /etc/rc.d/init.d/537_boot /etc/rc.d/rc5.d/S99537_boot
}
elif [ -a /etc/debian_version ]; then
{
   if [ -a ./hamregistry.bin ]; then
   {
      mv -f /etc/hamregistry.bin /etc/hamregistry.bak
      cp ./hamregistry.bin /etc/hamregistry.bin
   }
   else
   {
      rm -f /etc/hamregistry.bin
   }
   fi
   echo installing hamregistry, used for persistant storage
   install -o root -g root -m 110 hamregistry /usr/sbin
   echo installing usrsound, a soft buzzer
   install -o root -g root -m 755 usrsound /usr/sbin
   echo installing ham module
   install -o root -g root -m 664 537.o ${CharModDir}/537.o || exit 1
   echo installing hamcore module
   install -o root -g root -m 664 537_core.o ${CharModDir}/537_core.o || exit 1

   echo debian 537_boot rc2.d and rc3.d scripts
   install -o root -g root -m 110 537_boot /etc/init.d || exit 1
   ln -s -f /etc/init.d/537_boot /etc/rc2.d/S99537_boot
   ln -s -f /etc/init.d/537_boot /etc/rc3.d/S99537_boot
}
elif [ -a /etc/slackware-version ]; then
{
   if [ -a ./hamregistry.bin ]; then
   {
      mv -f /etc/hamregistry.bin /etc/hamregistry.bak
      cp ./hamregistry.bin /etc/hamregistry.bin
   }
   else
   {
      rm -f /etc/hamregistry.bin
   }
   fi
   echo installing hamregistry,  used for persistant storage
   install -o root -g root -m 110 hamregistry /usr/sbin
   echo installing usrsound, a soft buzzer
   install -o root -g root -m 755 usrsound /usr/sbin
   echo installing ham module
   install -o root -g root -m 664 Intel537.o ${CharModDir}/Intel537.o || exit 1

   echo seting up slackware 537_boot script
   install -o root -g root -m 110 537_boot /etc/rc.d || exit 1
   if ! grep 537_boot /etc/rc.d/rc.local > /dev/null 2> /dev/null; then
   {
      echo "/etc/rc.d/537_boot start" >> /etc/rc.d/rc.local
   }
   fi
}
elif [ -a /etc/bluepoint-release ]; then
{
   if [ -a ./hamregistry.bin ]; then
   {
      mv -f /etc/hamregistry.bin /etc/hamregistry.bak
      cp ./hamregistry.bin /etc/hamregistry.bin
   }
   else
   {
      rm -f /etc/hamregistry.bin
   }
   fi
   echo installing hamregistry, used for persistant storage
   install -o root -g root -m 110 hamregistry /usr/sbin
   echo installing usrsound, a soft buzzer
   install -o root -g root -m 755 usrsound /usr/sbin
   echo installing ham module
   install -o root -g root -m 664 Intel537.o ${CharModDir}/Intel537.o || exit 1

   echo bluepoint 537_boot rc2.d, rc3.d, and rc5.d scripts
   install -o root -g root -m 110 537_boot /etc/rc.d/init.d || exit 1
   ln -s -f /etc/rc.d/init.d/537_boot /etc/rc.d/rc2.d/S99537_boot
   ln -s -f /etc/rc.d/init.d/537_boot /etc/rc.d/rc3.d/S99537_boot
   ln -s -f /etc/rc.d/init.d/537_boot /etc/rc.d/rc5.d/S99537_boot
}
else
{
   if [ -a ./hamregistry.bin ]; then
   {
      mv -f /etc/hamregistry.bin /etc/hamregistry.bak
      cp ./hamregistry.bin /etc/hamregistry.bin
   }
   else
   {
      rm -f /etc/hamregistry.bin
   }
   fi
   echo installing hamregistry,  used for persistant storage
   install -o root -g root -m 110 hamregistry /usr/sbin
   echo installing usrsound, a soft buzzer
   install -o root -g root -m 755 usrsound /usr/sbin
   echo installing ham module
   install -o root -g root -m 664 Intel537.o ${CharModDir}/Intel537.o || exit 1

   echo unknown distribution. no boot scripts installed
   exit 1
}
fi
echo starting module and utilities
/bin/bash 537_boot restart
echo done

