#!/bin/sh
# Autor:Jorge Ferrer (jferrer@ieeesb.etsit.upm.es),
# Version:0.1 , 24-11-96
# Version:0.2 ,  6- 9-97
# Version actual: 0.3 23 Nov 98

# FUTUROS CAMBIOS:
# -Control de errores

# -- Declaracion de constantes --
TITULO="AGASSI's HELP"
DIR_MANUALES="/usr/local/lib/agassi/"
#
# -- Inicializacion de variables --
SALIR="no"
VOLVER="no"
SECCION=""
#La pantalla tiene normalmente 80x25
ALTO_DIALOG="7"
ANCHO_DIALOG="30"
ALTO_MENU="21"
ANCHO_MENU="62"
#N_MANUALES max depende de ALTO_MENU. ALTO_MENU=20 =>N_MANUALESmax=11
N_MANUALES="12"
ANCHO="78"
ALTO="24"
MSG=""

#----------------------- COMENTARIOS ----------------------------------------
# Para ver todas las posibilidades de "dialog"
# consulta su pagina del manual escribiendo: man dialog

#-----------------------------------------------------------------------------
#-------------------------- MENUS DE TUTORIALES ------------------------------

function MenuUsuario () {
VOLVER="no";SALIR="no";SECCION="Usuario"
dialog --clear --title "$TITULO" \
     	--menu " Estos son una serie de manuales ideados para \n\
 novatos en linux. \n\
 Elige el manual que prefieras :" "$ALTO_MENU" "$ANCHO_MENU" "$N_MANUALES" \
        "1 Intro"	"Introduccion a Linux" \
	"2 Comandos"  	"Comandos usuales de Linux" \
	"3 Avanzado"	"Redireccionamiento,job control..."\
	"4 Pine"	"Lector de correo"\
        "5 Joe" 	"Sencillo editor de texto" \
	"6 Vi" 		"Breve tutorial del editor vi" \
	"7 Emacs"	"El editor mas potente que existe"\
	"8 Shell"       "Que es una Shell y mas"\
	"9 Configura"   "Configuracion de usuario de Shell y X"\
	"Volver"	"Volver al menu inicial"\
	"Salir"      	"Salir al shell" 	2> /tmp/menu.tmp.$$

retval=$?
opcion=`cat /tmp/menu.tmp.$$`
rm -f /tmp/menu.tmp.$$

case $retval in
  0)case $opcion in
	'1 Intro') dialog --msgbox "Este manual es uno de los que corren ms\
 prisa. Animate a hacerlo TU" "$ALTO_DIALOG" "$ANCHO_DIALOG";;
	'2 Comandos') dialog --backtitle "$TITULO" \
		--textbox "$DIR_MANUALES"/$SECCION/comandos.tut "$ALTO" "$ANCHO";;
	'3 Avanzado') dialog --backtitle "$TITULO" \
		--textbox "$DIR_MANUALES"/$SECCION/avanzado.tut "$ALTO" "$ANCHO";;
	'4 Pine')dialog --msgbox "Este manual es uno de los que corren ms\
 prisa. Animate a hacerlo TU" "$ALTO_DIALOG" "$ANCHO_DIALOG";;
	'5 Joe')dialog --msgbox "Este manual es uno de los que corren ms\
 prisa. Animate a hacerlo TU" "$ALTO_DIALOG" "$ANCHO_DIALOG";;
	'6 Vi')  dialog --backtitle "$TITULO" \
		--textbox "$DIR_MANUALES"/$SECCION/vi.tut "$ALTO" "$ANCHO";;
	'7 Emacs') dialog --backtitle "$TITULO" \
		--textbox "$DIR_MANUALES"/$SECCION/emacs.tut "$ALTO" "$ANCHO";;
	'8 Shell')dialog --backtitle "$TITULO" \
		--textbox "$DIR_MANUALES"/$SECCION/shell.tut "$ALTO" "$ANCHO";;
        '9 Configura') dialog --backtitle "$TITULO" \
                --textbox "$DIR_MANUALES"/$SECCION/configuracion_usuario.tut "$ALTO" "$ANCHO";;
	'Volver') VOLVER="si";;
	'Salir') VOLVER="si";SALIR="si";;
    esac
	;;
  1)VOLVER="si";;
  255) SALIR="si"
    MSG="Que es eso de pulsar ESC, es que ya lo sabes todo???";;
esac
}
#-----------------------------------------------------------------------------
function MenuAdm () {
VOLVER="no";SALIR="no";SECCION="Adm"
dialog --clear --title "$TITULO" \
       --menu "Estos tutoriales estan pensados para administradores de \
sistemas Linux y usuarios que instalan Linux en su ordenador personal"\
	"16" "63" "7" \
	"1 Varios"	"Utilidades varias para el administrador"\
	"2 Kernel"	"Compilacin del Kernel de Linux"\
        "3 PPP"         "Configuracin de PPP"\
        "4 Booting"     "Todo sobre el arranque de un ordenador"\
        "5 BootConf"    "Configurando el arranque(LILO,boot disk,...)"\
        "Volver"        "Volver al menu de inicio"\
        "Salir"         "Salir al shell"        2> /tmp/menu.exp.tmp.$$

retval=$?
opcion=`cat /tmp/menu.exp.tmp.$$`
rm -f /tmp/menu.exp.tmp.$$

case $retval in
  0)case $opcion in
	'1 Varios') dialog --backtitle "$TITULO"\
		--textbox "$DIR_MANUALES"/$SECCION/adm.tut "$ALTO" "$ANCHO";;
	'2 Kernel') dialog --backtitle "$TITULO"\
		--textbox "$DIR_MANUALES"/$SECCION/kernel.tut "$ALTO" "$ANCHO";;
	'3 PPP') dialog --backtitle "$TITULO"\
		--textbox "$DIR_MANUALES"/$SECCION/ppp.tut "$ALTO" "$ANCHO";;
	'4 Booting') dialog --backtitle "$TITULO"\
	 	--textbox "$DIR_MANUALES"/$SECCION/booting.tut "$ALTO" "$ANCHO";;
	'5 BootConf') dialog --backtitle "$TITULO"\
	 	--textbox "$DIR_MANUALES"/$SECCION/bootconf.tut "$ALTO" "$ANCHO";;
	'Volver')VOLVER="si" ;;
	'Salir') SALIR="si" ; VOLVER="si";;
    esac  ;;
  1)VOLVER="si";;
  255)VOLVER="si";SALIR="si";;
esac
}
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
#-----------------------------------------------------------------------------
function MenuProgramacion () {
VOLVER="no";SALIR="no"
SECCION="Programacion"
dialog --clear --title "$TITULO" \
       --menu "Estos manuales estan pensados para usuarios que \n\
quieran instalar y configurar su S.O. Linux.\n\
Elige uno de los siguientes manuales:"	"16" "$ANCHO_MENU" "6" \
	"1 Bash"	"El lenguaje de la Bourne Shell Again"\
	"2 Tcsh"	"El lenguaje de la shell Tcsh"\
	"3 Tcl-tk"	"El lenguaje TCL-TK"\
	"4 Perl"	"El lenguaje Perl"\
	"Volver"	"Volver al menu inicial"\
	"Salir"      	 "Salir al shell" 	2> /tmp/menu.exp.tmp.$$

retval=$?
opcion=`cat /tmp/menu.exp.tmp.$$`
rm -f /tmp/menu.exp.tmp.$$

case $retval in
  0)case $opcion in
        '1 Bash') dialog --backtitle "$TITULO" \
                --textbox "$DIR_MANUALES"/$SECCION/bash.tut "$ALTO" "$ANCHO";;
        '2 Tcsh') dialog --backtitle "$TITULO" \
                --textbox "$DIR_MANUALES"/$SECCION/tcsh.tut "$ALTO" "$ANCHO";;
	'3 Tcl-tk') dialog --backtitle "$TITULO" \
                --textbox "$DIR_MANUALES"/$SECCION/tcl-tk.tut "$ALTO" "$ANCHO";;
	'4 Perl') dialog --backtitle "$TITULO" \
                --textbox "$DIR_MANUALES"/$SECCION/perl.tut "$ALTO" "$ANCHO";;
	'Volver')VOLVER="si" ;;
	'Salir') SALIR="si" ; VOLVER="si";;
    esac  ;;
  1)VOLVER="si";;
  255)VOLVER="si";SALIR="si";;
esac
}
#----------------------------------------------------------------------------
#--------------------------- FUNCIONES EXTRA --------------------------------
function LoSiento () {
dialog --msgbox "Esta opcion no esta disponible\
 todavia. Prueba dentro de un tiempo" "$ALTO_DIALOG" "$ANCHO_DIALOG"
}
#-----------------------------------------------------------------------------
#------------------------- MENU INICIAL --------------------------------------
function Menu () {
VOLVER="no";SALIR="no"
dialog --clear --title "$TITULO" \
        --menu "         -- BIENVENIDO a la ayuda de agassi --\n\
 Usa los cursores para seleccionar una seccion y pulsa \n\
 <ENTER> para entrar en ella. " "16" "$ANCHO_MENU" "5" \
        "Usuario"  	"Tutoriales para usuarios" \
	"Administracion" "Como administrar un sistema Linux"\
        "Programacion"	"Lenguajes:bash, tcsh, tcl-tk,..." \
	" "		" "\
	"Salir"      	"Salir al shell" 	2> /tmp/menu.tmp.$$

#En /tmp/menu.tmp.$$ se ha guardado la eleccion del usuario, mientras que en
#la variable $? se indica:1=> error o has pulsado Cancel;0=>todo bien

retval=$?

opcion=`cat /tmp/menu.tmp.$$`
rm -f /tmp/menu.tmp.$$

case $retval in
  0)
    case $opcion in
	'Usuario')until test "$VOLVER" = "si" 
	   		do MenuUsuario
		    done ;; 
	'Administracion') until test "$VOLVER" = "si" 
	   		do MenuAdm
		    done ;; 
	'Programacion') until test "$VOLVER" = "si" 
	   		do MenuProgramacion
		    done ;;
	'Salir') SALIR="si" ;;
    esac
	;;
  1)
    SALIR="si"
    MSG="Como que Cancel, que pasa es que ya lo sabes todo???";;
  255)
    SALIR="si"
    MSG="Que es eso de pulsar ESC, es que ya lo sabes todo???";;
esac
}
# ------------------------------------------------------------------------
# ------------------------ PROGRAMA PRINCIPAL ----------------------------

until test "$SALIR" = "si"
	do Menu
done

clear
echo "$MSG"
