#!/bin/sh 
# 	$Id: dialog_main.sh,v 1.8 2004/10/15 01:38:23 saturnero Exp $	

if [ "`id -u`" != "0" ]; then
        echo "Sorry, this must be done as root."
        exit 1
fi

tempfile=`/usr/bin/mktemp -t checklist`

menu() {
    [ -f config.sh ] && . ./config.sh
    if [ $LOCALDIR ]; then
            cd $LOCALDIR && . ./config.sh
    else                
        files/dialogs/dialog_config.sh 
	if [ $? != 0 ]; then
		exit 1
	fi
	. ./config.sh
    fi                
    dialog --title "FreeSBIE Main Menu" --hline "Press F1 for Installation Guide" \
	--hfile "files/dialogs/freesbie_help" \
	--menu "Welcome to the FreeSBIE installation and configuration tool. Please \
	select one of the options below by using the arrow keys or typing the \
	first character of the option name you're interested in. Invoke an \
	option with [SPACE] or [ENTER]. To exit, use [TAB] to move to Exit." 22 73 11 \
    	Configure "Change current startup configuration" \
    	Rmdir "Clean the FreeSBIE FS" \
    	Mkdir "Create a new FreeSBIE FS" \
    	World "BuildWorld - Create a new World" \
    	Install "InstallWorld - Install new World" \
    	Kernel "Build & Install Kernel - Create & Install Kernel" \
    	Fixit "PatchFiles - Copy cool & useful files" \
    	Packages "Packages - Choose packages to install" \
    	User "Custom User - Install shell script files & others" \
    	Build "Build Iso - Compress filesystem create .iso file" \
	Restore "Restore - Restore previously compressed filesystem" \
    	EXIT "Quit" \
    2> $tempfile

    result=`cat $tempfile`
    
    case ${result} in
    
      Configure)
      cd $LOCALDIR && sh files/dialogs/dialog_config.sh
      ;;
      Rmdir)
      cd $LOCALDIR && sh $LOCALDIR/0.rmdir.sh
      ;;
      Mkdir)
      cd $LOCALDIR && sh $LOCALDIR/1.mkdir.sh
      ;;
      World)
      cd $LOCALDIR && sh $LOCALDIR/2.buildworld.sh
      ;;
      Install)
      cd $LOCALDIR && sh $LOCALDIR/3.installworld.sh
      ;;
      Kernel)
      cd $LOCALDIR && sh $LOCALDIR/4.kernel.sh
      ;;
      Fixit)
      cd $LOCALDIR && sh $LOCALDIR/5.patchfiles.sh
      ;;
      Packages)
      cd $LOCALDIR && sh $LOCALDIR/6.packages.sh
      ;;
      User)
      cd $LOCALDIR && sh $LOCALDIR/7.customuser.sh
      ;;
      Build)
      cd $LOCALDIR && sh $LOCALDIR/8.preparefs.sh && sh $LOCALDIR/81.mkiso.sh
      read dummy;
      ;;
      Restore)
      cd $LOCALDIR && sh $LOCALDIR/9.restorefs.sh
      ;;
      EXIT)
      exit 0
      ;;
      *)
      exit 1
      ;;      
    esac
    menu        
}
menu
