#!/bin/ash
# welcome (by M. Andreoli) 

#set -x

. /etc/color
. /etc/dialog.lib

TMP=/tmp/tmp$$

# FUNCTIONS
BACK_TITLE="MuLinux v`cat /etc/version` `tell Overview -compulsory-`"
have_dialog=
[ "`which dialog`" ] && have_dialog=yes
#have_dialog=

Info()
{
if [ "$have_dialog" ] ; then
       	dinfo -r 3 -c 50  ${TITLE:+ "-t $TITLE"} $@ 
else
	clear
	[ "$TITLE" ] && echo -e "${BRIGHT}${BLUE}$TITLE $NORMAL"
       	echo $@ 
fi
sleep 3 
}

Message()
{
case $1 in
p)
cat > $TMP
;;
*)
if [ "$have_dialog" ] ; then
	dmessage $(cat $TMP | quote)
else
	cat $TMP
fi
rm $TMP
;;
esac
}

askyn()
{
if [ "$have_dialog" ] ; then
dyesno ${TITLE:+ "-t $TITLE"} "$@?"
r=`result`
case $r in
-yes-)  return 0;;
*)      return 1;;
esac
else
        read -p "$@ (y/n)? [y]" a

case "Z${a}Z" in
ZyZ|ZZ)
        return 0;;
*)
        return 1;;
esac

fi

}


show_info()
{
[ -x /usr/bin/info ] || return
TITLE="`tell Hardware_Info`"
Info "`tell You may have it typing 'info'`"
/usr/bin/info 
}

show_help()
{
[ -x /usr/bin/help ] || return
TITLE="`tell Help_and_Docs`"
Info "`tell You may have them typing 'help' or F1`"
/usr/bin/help
}

start_mon()
{
TITLE="`tell System_Rustic_Monitor`"
Info "`tell You may have it typing 'mon'`"
mon
}


start_browser()
{

TITLE="`tell Starting_the_internal_Web_Browser`"
Info "`tell You may have it pressing 'browser' ... wait`"

        echo "GET /" | /usr/bin/nc -w 1 localhost 80 2>/dev/null 1>&2

        if [ $? -eq 0 ] ; then
                sleep 2 # wait for httpd coming up
                browser http://localhost/
        else
	      TITLE="`tell Warning`"
              Info "`tell Server web not running.`"
        fi
}

start_rcp()
{

TITLE="`tell Starting_Remote_Configuration_Program`"
Info "`tell This is the web front-end to muLinux Setup`"

        echo "GET /" | /usr/bin/nc -w 1 localhost 81 2>/dev/null 1>&2

        if [ $? -eq 0 ] ; then
                #sleep 2 # wait for httpd coming up
                browser http://localhost:81/
        else
              TITLE="Warning"
              Info "`tell Server RCP not running.`"
        fi
}



full_screen_setup()
{
TITLE="`tell Full_screen_setup`" 
Info "tell `You may have it typing 'setup'`" 
TITLE=
Info "`tell Setup is inspecting your computer :-)`"
setup
}

start_menu()
{
TITLE="Console_Menu" 
Info "`tell You may have it typing 'menu'`" 
menu
}

unix_basic()
{
TITLE="Login" 
Info "`tell Time to login now, but first ...`" 
dbrowse -t "UNIX_basics" /usr/doc/help/unix.basic 
}

restart_joke()
{
dyesno -t "Restart" "\
You must shut down and restart your computer\n\
before the new settings will take effect.\n\
\n\
Do you want restart your computer? " 

dmessage -t A_Joke "\
Hehe, no really! A little joke :)))\n\
Shutdown isn't never required, here:\n\
YOU ARE RUNNING LINUX! (a form of)\
"
sleep 2
}

clone_the_system()
{
dyesno  -t "Hard-Disk_Install" "\
\n\
If you wish, I can copy myself permanently in some\n\
hard-disk partition of yours. If you are a DOS user and\n\
never installed Linux, I suggest you to 'clone' muLinux\n\
in c:\linux, selecting the UMSDOS model.\n\
\n\
Because You can 'clone' the system from the prompt, typing\n\
'clone', You can skip this stage selecting NO.\
\n"

r=`result`
case "Z$r" in
Z-yes-)  clone ;;
esac

}


# MAIN

dyesno  -t "Starting_the_..._tour" "\
\n\
Usually, in a standard Linux distribution the starting\n\
point is 'to login in the system'. In muLinux, this is\n\
only the _final_ step, because, frankly speaking, since\n\
logged-in we have no much to do yet. Anyway ...\n\
\n\
This little voyage inside muLinux take place only at the\n\
first boot. If you like to activate it again, please type\n\
'welcome' at the prompt. Select NO to skip.\
\n"

r=`result`
case "Z$r" in
Z-no-)	exit ;;
esac


start_browser  
start_rcp  
start_menu
#wizard
restart_joke
unix_basic

clear

# End
