#!/bin/tcsh -f
# JLdL 11May24.
#
# Look at the mirror log files to see what has been going on.
#
# Build an egrep target to filter out non-data lines.
#
# Blank lines.
set t = "^[ 	]*"'$'
#
# Changes in the Debian trace files are irrelevant.
set t = "$t|^project/trace/"
set t = "$t|^.trace/"
#
# This is for the MX-Linux mirror.
set t = "$t|^TIME.txt"
#
# This is for the Debian-Backports mirror.
set t = "$t|^new.html"
set t = "$t|^removals.txt"
#
# This is for the Linux Kernel mirror.
set t = "$t|^linux/docs/man-pages/LATEST-IS"
set t = "$t|^.autosigner-last-run"
#
# This is for the Debian-Parrot mirror.
set t = "$t|^last-sync.stamp"
set t = "$t|^last-sync.txt"
set t = "$t|^misc/archive-size.txt"
#
# These are for rsync.
set t = "$t|^receiving file list "
set t = "$t|^sent [0-9]"
set t = "$t|^wrote [0-9]"
set t = "$t|^total size is "
set t = "$t|^MOTD:"
set t = "$t|^deleting "
set t = "$t|^[^ ]*/"'$'
set t = "$t|^Number of files"
set t = "$t|^Number of created files"
set t = "$t|^Number of deleted files"
set t = "$t|^Number of regular files"
set t = "$t|^Total file size"
set t = "$t|^Total transferr"
set t = "$t|^Literal data"
set t = "$t|^Matched data"
set t = "$t|^File list"
set t = "$t|^Total bytes"
#
# These are for debmirror.
set t = "$t|^Starting "
set t = "$t|^Mirroring to "
set t = "$t|^Arches: "
set t = "$t|^Dists: "
set t = "$t|^Sections: "
set t = "$t|^Including source."
set t = "$t|^Will clean up "
set t = "$t|^Pdiff mode: "
set t = "$t|^Attempting to get lo"
set t = "$t|^Get Release files."
set t = "$t|^Get Packages and Sou"
set t = "$t|^Get Contents files"
set t = "$t|^Update Contents files"
set t = "$t|^Parse Packages and S"
set t = "$t|^Download all files "
set t = "$t|^Get package file"
set t = "$t|^Downloaded .* in "
set t = "$t|^Everything OK."
set t = "$t|^All done."
set t = "$t|^Cleanup mirror."
set t = "$t|^Finished on "
set t = "$t|^\[[ ,0-9]*%\] Getting:.*/Release"
set t = "$t|^\[[ ,0-9]*%\] Getting:.*/Contents-"
set t = "$t|^Errors:"
set t = "$t|^ *Release signature "
#
# These are for wget.
set t = "$t|\.listing"
set t = "$t|^FINISHED"
set t = "$t|^Downloaded"
set t = "$t|^Error in server respo"
#set t = "$t|No such file"
#set t = "$t|^Starting"
#set t = "$t|Control connection cl"
#set t = "$t|Data transfer aborted"
#set t = "$t|The server"
#set t = "$t|Login incorrect"
#set t = "$t|Invalid PORT"
#set t = "$t|Last-modified header "
#set t = "$t|/\?[DMNS]=[AD]"
#set t = "$t|/ \["
#set t = "$t|/index.html"
#set t = "$t|/faq.html"
#set t = "$t|/old-news.html"
#set t = "$t|Host not found"
#set t = "$t|Connection timed out"
#set t = "$t|Network is unreachabl"
#set t = "$t|Unknown type"
#set t = "$t|No route to host"
#set t = "$t|^http://.*:80/robots."
#set t = "$t|^.*ERROR 404: Not Fou"
#
# Define a target to filter only the deletion lines.
set d = "^deleting "
#
# Look at each log file in turn.
foreach f ( `\ls -1 mirror*.log | egrep -v 'bymail.log|byssh.log'` )
    #
    # In verbose mode, show the downloaded files.
    if ( "$1" == "-v" ) then
	if ( `echo -n $f | wc -c` > 30 ) then 
	    echo "${f}:	downloaded data files:"
	else if ( `echo -n $f | wc -c` > 22 ) then 
	    echo "${f}:		downloaded data files:"
	else if ( `echo -n $f | wc -c` > 14 ) then 
	    echo "${f}:			downloaded data files:"
	else
	    echo "${f}:				downloaded data files:"
	endif
	cat $f | egrep -v "$t" | \more
	set iw = $<
    #
    # In deletion mode, count the deleted files.
    else if ( "$1" == "-d" ) then
	set n = `cat $f | egrep "$d" | wc -l`
	if ( `echo -n $f | wc -c` > 30 ) then 
	    echo "${f}:	deleted data files: $n"
	else if ( `echo -n $f | wc -c` > 22 ) then 
	    echo "${f}:		deleted data files: $n"
	else if ( `echo -n $f | wc -c` > 14 ) then 
	    echo "${f}:			deleted data files: $n"
	else
	    echo "${f}:				deleted data files: $n"
	endif
    #
    # In package mode, count the package files in the pool.
    else if ( "$1" == "-p" ) then
	set n = `cat $f | grep "^pool/" | egrep -v "$t" | wc -l`
	if ( `echo -n $f | wc -c` > 30 ) then 
	    echo "${f}:	downloaded data files: $n"
	else if ( `echo -n $f | wc -c` > 22 ) then 
	    echo "${f}:		downloaded data files: $n"
	else if ( `echo -n $f | wc -c` > 14 ) then 
	    echo "${f}:			downloaded data files: $n"
	else
	    echo "${f}:				downloaded data files: $n"
	endif
    #
    # In security mode, count the i386 and amd64 package files in the pool.
    else if ( "$1" == "-s" ) then
	set n = `cat $f | egrep '^pool/.*_all.deb$|^pool/.*_i386.deb$|^pool/.*_amd64.deb$' | wc -l`
	if ( `echo -n $f | wc -c` > 30 ) then 
	    echo "${f}:	downloaded data files: $n"
	else if ( `echo -n $f | wc -c` > 22 ) then 
	    echo "${f}:		downloaded data files: $n"
	else if ( `echo -n $f | wc -c` > 14 ) then 
	    echo "${f}:			downloaded data files: $n"
	else
	    echo "${f}:				downloaded data files: $n"
	endif
    #
    # In normal mode, count the downloaded files.
    else
	set n = `cat $f | egrep -v "$t" | wc -l`
	if ( `echo -n $f | wc -c` > 30 ) then 
	    echo "${f}:	downloaded data files: $n"
	else if ( `echo -n $f | wc -c` > 22 ) then 
	    echo "${f}:		downloaded data files: $n"
	else if ( `echo -n $f | wc -c` > 14 ) then 
	    echo "${f}:			downloaded data files: $n"
	else
	    echo "${f}:				downloaded data files: $n"
	endif
    endif
end
