#! /bin/sh
# Create a user unique lockfile
touch /tmp/`whoami`
MENU=/tmp/`whoami`
# Function to prevent the shell from exiting after execution
do_wait() {
echo -n "[Return]"
read R
}
# Create the main GUI
dialog --title "Alge Menu System v0.1 (by lucc@powertech.no)" \
--backtitle \
"  Host: $HOSTNAME  |  User: `whoami`  |  TTY: `tty`  |  `date "+%a %D"`" \
--menu "Hello `whoami`, and welcome to $HOSTNAME. \
The following programs are currently available \
via this menu: (Use the arrow keys to scroll)" 21 75 13 \
"About" "Information about the Alge Menu System" \
"Pine" "A Program for Internet News and Email" \
"Elm" "Interactive screen-oriented mailer program" \
"Tin" "Threaded Usenet reader and poster" \
"Gopher" "Browse through the gopher archives" \
"Lynx" "General purpose distributed information browser" \
"Telnet" "Connect to a remote computer" \
"Ftp" "File transfer, download files from the Internet" \
"Irc" "Internet Relay Chat, realtime group chat" \
"Talk" "Talk to a person in realtime via keyboard" \
"Finger" "User information lookup program" \
"Jed" "Emacs style editor with color support" \
"Pico" "Text editor in the style of the Pine Composer" \
"Top" "System Monitor, display top CPU processes" \
"Status" "Display System disk & memory statistics" \
"Users" "List users currently online" \
"MC" "Midnight Commander file manager (ala Norton)" \
"Man" "Linux Manual and Programmer's Pages" \
"Help" "Compilation of most common UNIX commands" \
"Exit" "Exit menu" 2> $MENU
SELECT="`cat $MENU`"
# The menu functions
if [ "$SELECT" = "About" ]; then
 dialog --title "About" \
 --backtitle "Alge Menu System v0.1 - Information Page" \
 --msgbox \
 "Alge Menu System v0.1 uses the dialog(1) package to create a user-interface \
 making it easier for novice users to navigate a UNIX system without getting \
 lost. Most important was design and ease of use, so anyone could find their \
 desired program by simply using the arrow keys and then hitting return. \
 The script itself is freeware, do whatever you like with it. \
 dialog version 0.6z (c) John Gatewood Ham, the other programs the \
 respective programmers/groups.\
 Special thanks to Patrick J. Volkerding for the Linux Slakware \
 setup scripts and John Gatewood Ham for dialog version 0.6z. \
 Regards, Luke Th. Bullock (lucc@powertech.no) Oslo, Norway, 05/13/97" 16 60
meny
fi
if [ "$SELECT" = "Pine" ]; then pine ; meny ;fi
if [ "$SELECT" = "Tin" ]; then clear ; tin -C ; meny ;fi
if [ "$SELECT" = "Gopher" ]; then gopher gopher.sn.no ; meny ;fi
if [ "$SELECT" = "Lynx" ]; then lynx ; meny ;fi
if [ "$SELECT" = "Ftp" ]; then
 dialog --title "FTP" --backtitle "File Transfer Program" \
 --inputbox "Enter hostname (ie ftp.host.somewhere.net) Press ESC to cancel." \
 8 70 2> ~/.ftp.box
 if [ $? = 1 -o $? = 255 ]; then
 WHERE="?"
 else
 WHERE="`cat ~/.ftp.box`"
 fi
 if [ "$WHERE" = "?" ]; then rm ~/.ftp.box ;meny
 else
 clear ; echo "Type quit to exit" ; ftp $WHERE ; rm ~/.ftp.box ; meny
 fi
fi
if [ "$SELECT" = "Irc" ]; then irc `whoami` irc.homelien.no ; meny ;fi
# We need an inputbox for talk
if [ "$SELECT" = "Talk" ]; then
 dialog --title "Talk" \
 --backtitle "Talk Gateway (person to person realtime talk)" \
 --inputbox \
 "To talk to a person on the same host, enter user, to talk to \
 a person on a remote machine, type user@hostname.net" 9 70 2> ~/.talk.box
 WHOM="`cat ~/.talk.box`"
 clear ; talk $WHOM ; rm ~/.talk.box ; meny
fi 
#
if [ "$SELECT" = "Jed" ]; then jed ; meny ;fi
if [ "$SELECT" = "Pico" ]; then pico ; meny ;fi
if [ "$SELECT" = "Top" ]; then top -s ; meny ;fi
# Display the summary via dialogs textbox..
if [ "$SELECT" = "Status" ]; then
 SYSBOX=~/.sys.box
 echo > $SYSBOX
 echo "Kernel:" >> $SYSBOX ; uname -a >> $SYSBOX
 echo >> $SYSBOX
 echo "Memory and Swap Stats:" >> $SYSBOX ; free >> $SYSBOX
 echo >> $SYSBOX
 echo "Disk and Filesystem Stats:" >> $SYSBOX ; df >> $SYSBOX
 dialog --title "System Statistics" --textbox $SYSBOX 25 80
 rm ~/.sys.box
 meny
fi
# Same as above
if [ "$SELECT" = "Users" ]; then 
 UBOX=~/.user.box
 echo "The following users are online at the moment:" > $UBOX
 w >> $UBOX
 echo >> $UBOX ; echo "Last 10 logins were:" >> $UBOX ; last -10 >> $UBOX
 dialog --title "Output Summary" --textbox $UBOX 25 80
 rm $UBOX ; meny 
fi
if [ "$SELECT" = "MC" ]; then mc -c ; meny ;fi
# Prompt for input, display the formated man page displayed via textbox
if [ "$SELECT" = "Man" ]; then
 dialog --backtitle "Linux Manual Pages & Programmers Guide" \
 --title "Linux Manual" --inputbox "To read a manual page, enter the name \
 of the page. Defaults to \"man\" if there is no input, (even if cancel is \
 selected)." \
 9 65 2> ~/.mans
 if [ $? = 1 -o $? = 255 ]; then
 SMAN="man"
 else
 SMAN="`cat ~/.mans`"
 fi
 man $SMAN > ~/.manpage
 dialog --title "Manpage for $SMAN" --textbox ~/.manpage 25 80
 rm ~/.mans ~/.manpage ; meny
fi
# Prompt for input, display the finger output via textbox 
if [ "$SELECT" = "Finger" ]; then
 FINGINF=~/.finginf
 dialog --backtitle "Finger Gateway" \
 --title "Finger" --inputbox "To request finger information on a local user \
 type \"user\", if the user is on a remote host, enter the complete email \
 address (user@somewhere.net). If no input, fingers host." \
 10 65 2> ~/.tmp.fing
 TFING="`cat ~/.tmp.fing`"
 echo > $FINGINF 
 echo "The following information was retrieved for $TFING:" >> $FINGINF
 finger $TFING >> $FINGINF 
 dialog --title "Finger output summary" --textbox $FINGINF 25 80
 rm $FINGINF ; meny
fi
# Telnet prompt 
if [ "$SELECT" = "Telnet" ]; then
 dialog --backtitle "Telnet Gateway" \
 --title "Telnet" --inputbox "To connect to a remote computer, enter the \
 computer name below (ie machine.somewhere.net) Press ESC to cancel." \
 9 65 2> ~/.tmp.telnet
  if [ $? = 1 -o $? = 255 ]; then
   TELNET="?"
  else
   TELNET="`cat ~/.tmp.telnet`"
  fi
   if [ "$TELNET" = "?" ]; then
   rm ~/.tmp.telnet ;meny
  else
   clear ; echo "Usage: open host.somewhere.net, or type quit to exit..."
   telnet $TELNET ; rm ~/.tmp.telnet ; meny
  fi
fi
# Display a predefined textfile..
if [ "$SELECT" = "Help" ]; then
 dialog --title "Unix Commands (use / to perform a word search)." \
 --textbox "/usr/doc/unixhelp.txt" 25 80
 meny
fi
#
if [ "$SELECT" = "Exit" ]; then rm /tmp/`whoami` ; reset ; exit ;fi
#
# End, hope you enjoyed the reading ;)
