#!/bin/sh
# $Header: /home/kbackup/CVSROOT/KBackup/src/checkprogs,v 1.10 1997/09/19 19:49:25 kbackup Exp $
#
# This file is Copyright (C) 1995-1997 by Karsten Ballder (Ballueder@usa.net)
#
# It is part of the KBackup package, see the file COPYING for details.
# KBackup and all files included in this package are licensed and protected
# under the terms and conditions of the GNU General Public License Version 2.
#
#	If you want to contact the current maintainer of this software, please
#	send e-mail to: KBackup@usa.net
#       Or visit the KBackup-Homepage at http://KBackup.home.ml.org/
#
#
HasSED=NO
HasDIALOG=NO
HasTAR=NO
HasAFIO=NO
HasAFIO242=NO
HasFGREP=NO
HasGREP=NO
HasDD=NO
HasNot=
MYDIALOGTITLE="KBackup"

export HasSED HasDIALOG HasTAR HasAFIO HasDD HasNot
mydialog()
{
	dialog --backtitle "$MYDIALOGTITLE" "$@"
}

check_progs()
{	
	clear
	echo -n "Checking for required programs: "

	if [ "$TTYMODE" != YES ]
	then
		echo -n "$DIALOG "
		$DIALOG 2>/dev/null
		if [ $? != 127 ] ;then HasDIALOG=YES ; else HasNot="$HasNot $DIALOG";fi

		if [ $HasDIALOG = YES ]
		then
			$DIALOG --backtitle "test" --infobox "test" 5 20 2>/dev/null && clear 
			if [ $? = 0 ]
			then
				DIALOG=mydialog
			fi
		fi
	
		clear
		echo -n "Checking for required programs: "
		echo -n "$DIALOG "
	else
		DIALOG=mydialog
	fi
	
	echo -n "$SED "
	$SED 2>/dev/null
	if [ $? != 127 ] ;then HasSED=YES ; else HasNot="$HasNot $SED";fi
	
	echo -n "$FGREP "
	$FGREP 2>/dev/null
	if [ $? != 127 ] ;then HasFGREP=YES ; else HasNot="$HasNot $FGREP";fi
	
	echo -n "$GREP "
	$GREP 2>/dev/null
	if [ $? != 127 ] ;then HasGREP=YES ; else HasNot="$HasNot
	$GREP";fi
	
	echo -n "$TAR "
	$TAR 2>/dev/null
	if [ $? != 127 ] ;then HasTAR=YES ; else HasNot="$HasNot $TAR";fi
	
	echo -n "$AFIO "
	$AFIO 2>/dev/null
	if [ $? != 127 ]
	then 
		HasAFIO=YES 
		$AFIO -V | $SED '1,$ s/^.*Version \([0-9][0-9]*\)\.\([0-9][0-9]*\)\.\([0-9][0-9]*\) .*$/a=\1;b=\2;c=\3/g' >/tmp/.tmp$$
		. /tmp/.tmp$$
		rm -f /tmp/.tmp$$
		ver=`expr \( \( $a \* 100 \) + $b \) \* 100 + $c `
		if [ $ver -gt 20401 ]
		then
			HasAFIO242=YES
			echo -n "(2.4.2 or newer) "
		fi
	else
		HasNot="$HasNot $AFIO"
	fi

	echo "$DD "
	$DD 2>/dev/null </dev/null
	if [ $? != 127 ] ;then HasDD=YES ; else HasNot="$HasNot $DD";fi
	
	if [ $HasDIALOG != YES -a "$TTYMODE" != YES ]
	then
		echo -e "\n\aCannot find dialog program!
Running in simple shell mode instead.

Press Enter to continue..."
		read
	fi

	if [ $HasDIALOG = NO -o "$TTYMODE" = YES ] && [ "$DIALOG_SRC_FILE" != "" ]
	then
		echo -e "\tLoading dialog-emulation script..."
		. "$DIALOG_SRC_FILE"
		DIALOG=mydialog
	fi
}

report_missing()
{
	if [ "$HasNot" != "" ]
	then
		echo "
The following programs are not installed or their paths are not set
properly. For full functionality of KBackup you should install them.

missing: $HasNot
"
		if [ "$1" != "-noprompt" ]
		then
			echo -en "\aPress RETURN key to continue anyway..."
			read
		fi
	fi
}

