#!/bin/msh
N="
"
echo $@ | grep trace && set -x
echo $@ | grep echo && set -v
while :
do
	dlginput=`dialog --stdout --backtitle "Wizzysysinfo" --title "Main Menu" --cancel-label "Quit" --menu "" 0 0 0 \
	"RAM" "display RAM info" \
	"CPU" "display CPU info" \
	"version" "Display your DS Firmware and your DSLinux version" \
	"IP" "Display your IP" \
	"processes" "Display running processes" \
	"binaries" "Display all binaries in \$PATH" \
	"status" "Display daemon status" \
	"messages" "display system messages" \
	"hinged" "display hinged log" \
	"ntpclient" "display ntpclient log" \
	"samba" "display smb log" \
	--infobox "Please wait..." 0 0`
	case $? in
		1|255) exit 0 ;;
	esac
	case "$dlginput" in
		RAM)
			dialog --stdout --backtitle "Wizzysysinfo" --title "RAM" --msgbox "`cat /proc/meminfo`" 0 0
			;;
		CPU)
			dialog --stdout --backtitle "Wizzysysinfo" --title "CPU" --msgbox "`cpu`${N}${N}`cat /proc/cpuinfo`" 0 0
			;;
		version)
			dialog --stdout --backtitle "Wizzysysinfo" --title "version" --msgbox "Firmware:${N}`fwver | sed 's/ detected.  It is safe to run online games.//g'`${N}${N}Linux:${N}`cat /proc/version`${N}${N}DSLinux:${N}`cat /etc/version`${N}`grep Revision /etc/revision`" 0 0
			;;
		IP)
			dialog --stdout --backtitle "Wizzysysinfo" --title "IP" --msgbox "Internal IP: `getip`${N}External IP: `wget -q www.whatismyip.org -O -`" 0 0
			;;
		processes)
			ps aux > /tmp/psaux
			dialog --exit-label Ok --help-button --help-label Kill --textbox /tmp/psaux 0 0
			case $? in
				2)
					dlginput=`dialog --stdout --backtitle "Wizzysysinfo" --title "Kill" --inputbox "What to kill? (name or pid)" 0 0`
					dlginput2=`dialog --stdout --backtitle "Wizzysysinfo" --title "Kill" --menu "Which signal should be sent (default: SIGTERM)" 0 0 0 \
					"SIG0" "" \
					"SIGALRM" "" \
					"SIGHUP" "" \
					"SIGINT" "" \
					"SIGKILL" "" \
					"SIGPIPE" "" \
					"SIGPOLL" "" \
					"SIGPROF" "" \
					"SIGTERM" "" \
					"SIGUSR1" "" \
					"SIGUSR2" "" \
					"SIGVTALRM" "" \
					"SIGSTKFLT" "" \
					"SIGPWR" "" \
					"SIGWINCH" "" \
					"SIGCHLD" "" \
					"SIGURG" "" \
					"SIGTSTP" "" \
					"SIGTTIN" "" \
					"SIGTTOU" "" \
					"SIGSTOP" "" \
					"SIGCONT" "" \
					"SIGABRT" "" \
					"SIGFPE" "" \
					"SIGILL" "" \
					"SIGQUIT" "" \
					"SIGSEGV" "" \
					"SIGTRAP" "" \
					"SIGSYS" "" \
					"SIGEMT" "" \
					"SIGBUS" "" \
					"SIGXCPU" "" \
					"SIGXFSZ" ""`
					if echo $dlginput | grep -q [:alpha:]; then
						killall $dlginput
					else
						kill $dlginput
					fi  
			esac
			rm /tmp/psaux
			;;
		binaries)
			dialog --title "binaries" --backtitle "Wizzysysinfo" --msgbox "`OLDIFS="$IFS"; IFS=":"; ls $PATH; IFS="$OLDIFS"`" 30 23
			;;
		status)
			dialog --stdout --backtitle "Wizzysysinfo" --title "status" --msgbox "`for i in boa esd hinged inadyn inetd ntpclient openvpn syslogd; do /etc/rc.d/$i status; done`" 0 0
			;;
		messages)
			dialog --stdout --backtitle "Wizzysysinfo" --msgbox "Press q to exit, use the X and Y keys on your DS to scroll." 0 0
			less /var/log/messages
			;;
		hinged)
			dialog --stdout --backtitle "Wizzysysinfo" --msgbox "Press q to exit, use the X and Y keys on your DS to scroll." 0 0
			less /var/log/hinged.log
			;;
		ntpclient)
			dialog --stdout --backtitle "Wizzysysinfo" --msgbox "Press q to exit, use the X and Y keys on your DS to scroll." 0 0
			less /var/log/ntpclient.log
			;;
		samba)
			dialog --stdout --backtitle "Wizzysysinfo" --msgbox "Press q to exit, use the X and Y keys on your DS to scroll." 0 0
			less /var/log/smb_log.nmbd
			;;
	esac
done
exit 0

