#!/bin/sh
# @vasm: vasm-init
# @level: root
# @description: setup the initialisation script
# 
# (c) Kocil, 2003
# (c) Vector Linux, 2003

dbug() {
  echo $*
}

# must be root !
if [ ! "$UID" = "0" ]; then
$DCMD --backtitle "Vector Linux Software Ltd." \
--title " SORRY " --msgbox \
"\nThis is a root only configurator. Please login as root, use su, or sudo" 0 0
  exit
fi

if [ ! $DISPLAY = "" ]; then
DCMD="Xdialog --wrap" 
CMD="rxvt -e "
BACKTITLE=""
else
DCMD="dialog"
CMD=""
BACKTITLE="Vector Linux in the speed of light"
fi

check()
{
   if [ -x /etc/rc.d/rc.$1 ]; then
     echo on
   else
     echo off
   fi
}


fmenu=`mktemp -q /tmp/cdmenu.XXXXXX` && freply=`mktemp -q /tmp/cdreply.XXXXXX`
if [ $? != 0 ]; then
   echo Can not create temp file 
   exit 1
fi

echo '$DCMD --backtitle "$BACKTITLE" \
  --title "System Init Menu" --checklist \
"\nThis configurator allows you to enable initialisations scripts 
for booting up the system. Please select the necessary items
only to make your beloved Linux system lighter and faster.\n" 23 70 12 \' > $fmenu
echo 'swap    "Mount swap file"' `check serial` \\ >> $fmenu
echo 'fsck    "Check file system for errors"' `check fsck` \\ >> $fmenu
echo 'rtclock "Synchronize time using hardware clock"' `check rtclock` \\ >> $fmenu
echo 'random  "Seed random number generator"' `check random` \\ >> $fmenu
echo 'pnp     "Initialize Plug & Play system"' `check pnp` \\ >> $fmenu
echo 'hotplug "Make USB ready for new devices"' `check hotplug` \\ >> $fmenu
echo 'pcmcia  "Make PCMCIA ready for a new card (laptop)"' `check pcmcia` \\ >> $fmenu
echo 'kudzu   "Detect new hardware on booting"' `check kudzu` \\ >> $fmenu
echo 'modules "Load various kernal modules"' `check modules` \\ >> $fmenu
echo 'keymap  "Set the keyboard mapping"' `check modules` \\ >> $fmenu
echo 'serial  "Initialize serial ports"' `check serial` \\ >> $fmenu
echo 'inet    "Set basic networking"' `check inet` \\ >> $fmenu
echo " 2> $freply " >> $fmenu

. $fmenu

if [ $? -gt 0 ]; then
   exit 1
fi

dbug `cat $freply`

for script in swap fsck rtclock random pnp hotplug pcmcia kudzu modules keymap serial inet
do
  COUNT=`grep -c $script $freply`
  if [ "$COUNT" = "0" ]; then
     chmod a-x /etc/rc.d/rc.$script
     dbug disable $script
  else
     chmod a+x /etc/rc.d/rc.$script
     dbug enable $script
  fi
done

rm $fmenu
rm $freply

$DCMD --backtitle "$BACKTITLE" \
--title " DONE " --msgbox \
"\nYour system initialisation has been configured.
It will be used on the next booting" 0 0

