#!/bin/sh
# VASM
# Vector Linux System Menu
# 
# (c) Vector Linux, 2003

if [ ! $DISPLAY = "" ]; then
  DCMD="Xdialog --wrap" 
  CMD="rxvt -e "
  BACKTITLE=""
else
  DCMD="dialog"
  CMD=""
  BACKTITLE="Vector Linux ... at the speed of light"
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

dbug() {
  echo $* > /dev/null
}

clean_exit()
{
   rm -f $freply
   rm -f $fmenu
   exit 1
}

pcmciaset()
{
   chmod +x /etc/rc.d/rc.pcmcia  
  $DCMD --title "PCMCIA ACTIVATED" --msgbox \
"\nPCMCIA services are nowactivated \n
and will be available on your next boot of the system." 10 60
  
}

cupset()
{
  if [ ! -x /usr/sbin/cupsd ]; then
    $DCMD --title "CUPS PRINTER SYSTEM NOT INSTALLED" --msgbox \
"\nPlease install the cups printing system as it is not installed on your system.\n
Then return to this menu for configuration." 0 0
  else
    if [ ! $DISPLAY = "" ]; then
#     exec kcmshell printmgr
      firebird http://localhost:631 || mozilla http://localhost:631 & 
    else
      lynx http://localhost:631
    fi
  fi
}


while [ 0 ]; do

if [ "$UID" = "0" ]; then

 $DCMD --backtitle "$BACKTITLE" --title "Vector Linux System Menu (root mode)" \
--menu \
"Welcome to Vector Linux's System menu. \n\n
Use the cursor [up] [down] keys to navigate the menu. 
Press the [enter] key to make a selection."  20 76 12 \
"KEYMAP" "remap 'KEYBOARD'. The default is US English" \
"COMSET" "setup 'MOUSE' and 'MODEM' devices" \
"AUTOSET" "autosetup mouse,X,netcard,cdroms and sound card" \
"XSETUP" "setup 'X WINDOWS'. If you get stuck: CTRL+ALT+BS" \
"XTEXT"  "setup 'X Windows'. If the GUI config didn't work" \
"XBOOT"  "setup to boot into GUI mode. X must be working first" \
"XDMSET"   "setup X display manager for GUI mode login" \
"XWMSET"   "setup window manager launched from console (startx)" \
"XMENUSET" "setup the menu of XwmMenu" \
"XICONSET" "Setup icon theme for various window managers" \
"CDSET"  "setup 'CD-ROM' device. DVD, CD-R, CD-R/W, etc" \
"TIME"   "Set the PC to local or universal time zone" \
"LILO"   "setup 'LILO' the linux boot loader" \
"NETWORK" "setup 'NETWORK'.Settings and card configuration" \
"GATEWAY" "Setup internal network GATEWAY configuration" \
"PPPSET"  "setup 'DIAL-UP'. PPP, ISP's phone number, etc" \
"SRVMENU"  "Menu to add/remove services from boot time" \
"PCMCIA"  "Start PCMCIA service for laptop computers" \
"MODULES" "setup 'DRIVERS'. [F2] to save & [ESC] to exit" \
"SOUND"   "setup 'SOUND'. ISA pnp & PCIsound cards" \
"PRINTER"  "setup 'PRINTER'. Make the printer print" \
"PKGTOOL"  "The Slackware package system" \
"ADMIN"  "Add/delete or change password of users on the system" \
"EXIT"   "To quit system menu" 2> $freply

else

 $DCMD --backtitle "$BACKTITLE" --title "Vector Linux System Menu (user mode)" \
--menu \
"Welcome to Vector Linux's System menu.\n
More menu would be available if you call this programs as root\n\n
Use the cursor [up] [down] keys to navigate the menu. 
Press the [enter] key to make a selection."  18 76 6 \
"XWMSET"   "setup window manager launched from console (startx)" \
"XMENUSET" "setup the menu of XwmMenu" \
"XICONSET" "Setup icon theme for various window managers" \
"ADMIN"  "Change your password" \
"EXIT"   "To quit system menu" 2> $freply

fi

 if [ $? = 1 -o $? = 255 ]; then
   clean_exit
 fi

 MAINSELECT="`cat $freply`"

 # Start checking what to do. Some modules may reset MAINSELECT to run the
 # next item in line.
debug $MAINSELECT
 
case "$MAINSELECT" in
  "KEYMAP") 
    /sbin/kmapset
    ;;
  "COMSET")
    /sbin/comset
    ;;
  "AUTOSET")
    /sbin/vlautosetup
    ;;
  "XSETUP")
    if [ -x /usr/X11R6/bin/sax ]; then
	/usr/X11R6/bin/sax
    else
        /sbin/xf4config
    fi
    ;;    
  "XTEXT")
   /usr/X11R6/bin/xf86config
   ;;
  "XBOOT")
   /sbin/xboot
   ;;
  "XDM")
   /sbin/xdmset
   ;;
  "XWMSET")
   /usr/bin/xwmset
   ;;
  "XMENU")
   /sbin/xmenuset
   ;;
  "XICONSET")
   /usr/bin/xiconset
   ;;
  "CDSET")
   /sbin/cdset
   ;; 
  "TIME")
   $DCMD /usr/sbin/timeconfig
   ;;
  "LILO")
   /sbin/liloconfig
   ;;
  "PKGTOOL")
   pkgtool
   ;;
  "NETWORK")
   $CMD /sbin/netconfig
   ;;
  "GATEWAY")
   /sbin/netset
   ;;
  "PPPSET")
   /usr/sbin/pppsetup
   ;;
  "PCMCIA")
   pcmciaset
   ;;
  "SRVMENU")
   /sbin/srvmenu
   ;;
  "MODULES")
  $CMD mcedit /etc/rc.d/rc.modules
   ;;
  "PRINTER")
   cupset
   ;;
  "SOUND")
   $CMD /usr/sbin/sndconfig
   ;;
  "ADMIN")
    $CMD /sbin/vuser
   ;;
  "EXIT")
    clean_exit
   ;;
esac
done

clean_exit
