#!/bin/bash
#     Copyright (C) 2005, 2006 Stewart Adam
#    This file is part of FWVirusScanner.

#    FWVirusScanner is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.

#    FWVirusScanner is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.

#    You should have received a copy of the GNU General Public License
#    along with FWVirusScanner; if not, write to the Free Software
#    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
	pid="$2"
	check=$(ls /var/log/clamav/files.log;echo $?)
	for element in $check;do
		check1=$element
	done
	if [ "$check1" != "0" ]
	then
		kill "$pid"
		zenity --error --text "Internal Error: files.log does not exist."
		exit
	fi
	unset check
	unset check1

	check=$(ls /var/log/clamav/progress.log;echo $?)
	for element in $check;do
	check1=$element
	done
	if [ "$check1" != "0" ]
	then
	kill "$pid"
	zenity --error --text "Internal Error: progress.log does not exist."
	exit
	fi
	unset check
	unset check1

num=$(cat -n /var/log/clamav/files.log | awk '{printf $1 " " }')
	for element in $num;do
		totalscandir=$element
	done

	totalscanfiles="$1"
	let "totalscan = $totalscanfiles + $totalscandir"
sleep 5
(
while [ "$(ps -A | grep $pid)" != "" ];do
	check=$(ls /var/log/clamav/progress.log;echo $?)
	for element in $check;do
	check1=$element
	done
	if [ "$check1" != "0" ]
	then
	kill "$pid"
	fi
	unset check
	unset check1

	num2=$(cat -n /var/log/clamav/progress.log | awk '{printf $1 " " }')
	for element in $num2;do
	numscan=$element
	done

	currentscan=$(tail -n 1 /var/log/clamav/progress.log)
#	 | awk '{printf $1 "\b"}'
	currentscanbase=$(basename "$currentscan")
	echo "# Currently Scanning: $currentscanbase"
	let "perc = (($numscan*100 / $totalscan*100)/100)"
	echo $perc
	sleep 0.1
done
) | zenity --progress --auto-close --text "" --percentage="0" --title="Virus Scanner" --height "50" --width "200"
