#!/bin/sh
# full screen setup
# (C) M. Andreoli, for muLinux
#set -x

. /etc/utils

VERSION=`cat /etc/version`

other()
{
cat <<END

Other:
	probe: ide-hd ide-cdrom scsi-hd scsi-cdrom pci
	soft shutdown, soft restart
	system info, system help
END

}

wait()
{
echo "please, wait ..."
}


refresh()
{
TITLE="$1"
MSG="$2"

TITLE="\
                   VSETUP: muLinux Setup (full screen version) \
"

MSG="select a resource and press -ENTER-"



cat > /tmp/vsetup.cnt <<END 
:T: $TITLE 
:B: [r]econf | [p]rint val | [u]p | [d]own | [s]ave | [h]elp | [q]uit 
:S: $MSG
          _                   
 ___  ___| |_ _   _ _ __    _ 
/ __|/ _ \ __| | | | '_ \  (_)		full screen front-end
\__ \  __/ |_| |_| | |_) |  _ 		to Setup v$VERSION
|___/\___|\__|\__,_| .__/  (_)
                   |_|        
END
# addon's list
printf "Load the add-on: " >> /tmp/vsetup.cnt
echo >> /tmp/vsetup.cnt
for a in $(cat /setup/model/addons); do
printf "%3s " "$a" >> /tmp/vsetup.cnt
done
echo >> /tmp/vsetup.cnt
echo >> /tmp/vsetup.cnt

# resource list

i=1
for r in `cat /setup/model/custom`
do
include $r
status=${ACTION}
#setup $r requirement > /dev/null || status=skipped

case $status in
configure)	c=Y
		s=`setup $r status 2>/dev/null`
		;;
skip*)	   c=S;s=down;;
*)	   c=N;s=down;;
esac


UP="+"
DW="-"
UNK="?"
case Z${s}Z in
ZZ)	
	if [ $c = Y ] ; then
		s=$UP
	else
		s=$DW
	fi	
	;;

ZupZ)	s=$UP;;
ZdownZ)	s=$DW;;
esac

printf "%2s%2s %-12s " $c "$s" "$r"

[ "`expr $i % 4`" -eq 0 ] && echo 
i=`expr $i + 1`

done >>/tmp/vsetup.cnt
echo >> /tmp/vsetup.cnt
other >> /tmp/vsetup.cnt

kill -10 $pid 2>/dev/null 
}

process_link()
{
link=$1
case $link in
shutdown)
	setup -a shutdown stop
	;;
restart|all)
	setup -a custom
	;;
info)
	info
	wait
	;;
help)
	help
	wait
	;;
ide-hd)
	scan ide-hd
	;;
ide-cdrom)
	scan ide-cdrom
	;;
scsi-hd)
	scan scsi-hd
	;;
scsi-cdrom)
	scan scsi-cdrom
	;;
pci)
	scan pci
	;;
*)
	setup -f $link
	;;
esac

}



pid=$2
set -- $1
key=$1
link=$3

# first run

if [ -z "$key" ] ; then
echo "Working ...."
refresh
muless -e $0 -x /tmp/vsetup.cnt
exit
fi


case $key in
q)
	rm /tmp/vsetup.cnt
	exit 1
	;;

|r)
	clear
	process_link $link
	refresh
	;;	
d)
	clear
	setup $link stop 2>/dev/null
	refresh
	;;
u)
        clear
        setup $link
	refresh
        ;;
s)
        clear
        setup -s
        ;;
p)
	muless -e $0 -t "Configuration Params: $link" \
	-b "q) back" /setup/cnf/$link.cnf
	;; 
h)
	(
	echo
	setup $link info ) > /tmp/vsetup.hlp
	muless -e $0 -t "Help: $link" -b "q) back" /tmp/vsetup.hlp
	;;		
esac

