#!/bin/sh
# @vasm: vbootset
# @level: root
# @description: select default run level for booting
# 
# (c) Kocil, 2003
# (c) Vector Linux, 2003

VDIR=`dirname $0`
. $VDIR/vasm-functions

check_root

CONFIG="/etc/inittab"
BOOT_MODE="2"

get_bootmode()
{
   LINE=`grep -e "^id:[2-5]:initdefault:" $CONFIG`
   dbug boot_line $LINE
   if [ "$LINE" ]; then
      BOOT_MODE=`echo $LINE | cut -d : -f 2`         
   fi
   dbug boot_mode $BOOT_MODE
}

set_bootmode()
{
   cat $CONFIG | sed "s/^id:[2-5]:initdefault:/id:$BOOT_MODE:initdefault:/" > $CONFIG
}

boot_status()
{
   if [ "$1" = "$BOOT_MODE" ]; then
      echo "on"
   else
      echo "off"
   fi
}

###################################################
menuA()
{

get_bootmode

TITLE="BOOT MODE ADMINISTRATION"
TEXT="\n
This menu allows you to choose the default boot mode.\n
However, make sure that X-Windows has been setup\n
properly before using the GUI boot mode.\n\n
Use [space bar] to select the mode, then press OK."
DIMENSION="18 60 4"

$DCMD --backtitle "$BACKTITLE" --title "$TITLE" --radiolist \
"$TEXT" $DIMENSION \
2 "Text user interface desktop" $(boot_status 2) \
3 "Text user interface server" $(boot_status 3) \
4 "Graphical user interface desktop" $(boot_status 4) \
5 "Graphical user interface server" $(boot_status 5) \
2> $freply

[ ! $? = 0 ] && return $?
BOOT_MODE=`cat $freply`

case $BOOT_MODE in
  2|3|4|5)
     set_bootmode
     ;;
esac
return 0
}

########################################################
# MAIN PROGRAM
dbug "VBOOT"
menuA

