#!/bin/sh
# @vasm: HWSET
# @level: root
# @description: activate various initialisation 
# 
# (c) Kocil, 2003
# (c) Vector Linux, 2003

vdir=$(dirname $0)
. $vdir/vasm-functions

check_root

INIT_DIR="/etc/rc.d"

###################################################
INITS="pnp hotplug pcmcia serial alsa keymap udev"

init_desc()
{
case $1 in
udev) 
  echo "UDEV file system (kernel 2.6 up only)"
  ;;
pnp) 
  echo "ISA Plug and Play"
  ;;
pcmcia) 
  echo "PCMCIA card. Enable this for laptop"
  ;;
hotplug)
  echo "USB/PCI hotplug devices"
  ;;
alsa)
  echo "Advanced Linux Sound System"
  ;;
serial)
  echo "Serial TTY and modem"
  ;;
keymap)
  echo "Keyboard map"
  ;;
esac
}

###################################################
# return the service status for a runlevel
# $1 = init name
init_status()
{
   if [ -x /etc/rc.d/rc.$1 ]; then
        echo "on"
   else
        echo "off"
   fi
}

###################################################
select_init()
{
TITLE="HARDWARE INIT CONFIGURATOR"
TEXT="\n
In this configurator you may select the hardware\n
initialisations that should be performed during\n
system boot.\n\n
Please enable the hardware inits you wish."
DIMENSION="20 60 8"

echo '$DCMD --backtitle "$BACKTITLE" --title "$TITLE" --checklist "$TEXT" $DIMENSION \' > $fmenu

for RC in $INITS; do
  DESC=`init_desc $RC`
  STATE=`init_status $RC`
  echo $RC \"$DESC\" $STATE \\ >> $fmenu
done
echo ' 2> $freply ' >> $fmenu

. $fmenu

[ $? != 0 ] && return 1

if [ "$CMD" = "" ]; then
  CHOICES=`cat $freply | sed -e 's/"//g'`
else
  CHOICES=`cat $freply | sed -e 's!/! !g'`
fi

for RC in $INITS; do
  if echo $CHOICES | grep -qw $RC; then
    chmod +x /etc/rc.d/rc.$RC  
  else
    chmod -x /etc/rc.d/rc.$RC   
  fi
done
}

########################################################
# MAIN PROGRAM

echo "Service Configurator is starting ..."

select_init

clean_exit
