#!/bin/sh 
# Copyright (C) 2001 Open Source Telecom Corporation.
#
# This file is free software; as a special exception the author gives
# unlimited permission to copy and/or distribute it, with or without
# modifications, as long as this notice is preserved.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

if test -z "$DIALOG" ; then DIALOG=dialog ; fi



if test -z "$RELEASE" ; then
	mandrake=`cat /etc/redhat-release | grep Mandrake`
	redhat=`cat /etc/redhat-release | grep "RedHat"`
	if test ! -z "$mandrake" ; then
		RELEASE=Mandrake-7.2 
	elif test ! -z "$redhat" ; then
		RELEASE=RedHat-6.2
	fi
	if test -z "$RELEASE" ; then
		exit "*** cannot identify target system" ; fi
fi

export DIALOG RELEASE

case "$1"  in

Voices)
	$DIALOG --title "Select Voices" \
		--backtitle "for use with $RELEASE" \
		--menu "\
Select a voice library package to install.  You can install \
multiple voice libraries one at a time." \
		0 0 0 \
		"UsEngM" "US English Male" \
		"FrenchM" "French Male Speaker" \
		"FrenchF" "French Female Speaker" \
		2>/tmp/menu.tmp.$$
	retval=$?
	if "$retval" = "0" ; then
		retval=`cat /tmp/menu.tmp.$$`
		rpm -Uhv $RELEASE/bayonne-$retval
	fi
	exec $0
	;;
Options)
	$DIALOG --title "Select Options" \
		--backtitle "for use with $RELEASE" \
		--menu "\
Select optional packages and services to be installed \
on this machine" \
		0 0 0 \
		"BayonneDB" "Bayonne Database Services" \
		"Devel" "Development packages" \
		"Festival" "Festival TTS engine" \
		2>/tmp/menu.tmp.$$
	retval=$?
	if "$retval" = "0" ; then
		retval=`cat /tmp/menu.tmp.$$`
		rm -f /tmp/menu.tmp.$$
	fi
	pkglist=""
	case "$retval" in
	BayonneDB)
		pkglist="CommonC++ bayonnedb"
		;;
	Devel)
		pkglist="CommonC++ ccaudio ccscript ccrtp bayonne-devel"
		;;
	Festival)
		pkglist="festival"
		;;
	esac
	if test -z "$pkglist" ; then exec $0 ; fi
	rpmlist=""
	for pkg in $pkglist ; do
		rpmlist="$rpmlist `echo $RELEASE/$pkg-*`"
	done
	rpm -Uhv $rpmlist
	exec $0
	;;
Server)
	$DIALOG --title "Select Driver" \
		--backtitle "for use with $RELEASE" \
		--menu "\
Select your multiline telephony card or native \
driver interface, and the appropriate bayonne packages \
will be installed" \
		0 0 0 \
		"Dialogic" "Dialogic SDK" \
		"Modems" "Voice Modems" \
		"Pika"	"Pika MonteCarlo" \
		"Quicknet" "Quicknet Cards" \
		"RTP"	"RTP Trunking" \
		"VPB"	"Voicetronix Support" \
		2>/tmp/menu.tmp.$$
	retval=$?
	if "$retval" = "0" ; then
		retval=`cat /tmp/menu.tmp.$$`
		rm -f /tmp/menu.tmp.$$
	else
		exec $0
	fi
	pkglist="CommonC++ ccscript ccaudio ccrtp"
	case "$retval" in
	Dialogic)
		pkglist="$pkglist LiS bayonne-streams bayonne-dialogic" 
		;;
	Modem | Quicknet | RTP)
		pkglist="$pkglist bayonne-native"
		;;
	Pika)
		pkglist="$pkglist bayonne-native bayonne-pika"
		;;
	VPB)
		pkglist="pkglist vpb2 bayonne-native"
		;;
	*)
		pkglist=""
		;;
	esac
	if test -z "$pkglist" ; then exec $0 ; fi
	pkglist="$pkglist bayonne-common"
	$rpmlist=""
	for pkg in $pkglist ; do
		rpmlist="$rpmlist `echo $RELEASE/$pkg-*`"
	done
	rpm -Uhv $rpmlist	
	exec $0
	;;
*)
	$DIALOG --title "Install Bayonne" \
		--backtitle "for use with $RELEASE" \
		--menu "\
Select installation of a telephony server, \
of a supplimental language pack, or of \
an optional package" \
		0 0 0 \
		"Server" "Server and drivers" \
		"Options" "Optional Packages" \
		"Voices" "Voice Libraries" \
		2>/tmp/menu.tmp.$$
	retval=$?
	case "$retval" in
	0)
		choice=`cat /tmp/menu.tmp.$$`
		rm -f /tmp/menu.tmp.$$
		exec $0 $choice
		;;
	*)
		exit
		;;
	esac
	;;
esac
exit 0

