#! /bin/sh

# $Id$

#Make tables showing the progress of cloning (or squeezing) tapes.

#Get all the common stuff for migration, duplication and cloning reporting.
mig_com=`which migration_common 2> /dev/null`
if [ -z $mig_com ]; then
    #When run interactively, bash was picking the wrong version of
    # migration_common.  Even when 'which' was able to find the correct
    # one with the same environment.
    #
    #If 'which' didn't find it, next try the path of this script.

    mig_com=`dirname $0`/migration_common
    if [ ! -x "$mig_com" ]; then
        #If this fails, fall back to the old way.
	mig_com=migration_common
    fi
fi
source $mig_com

#Create the variables that point to the files to output to.
fname=CLONING_SUMMARY
old_output_file=$inventory_dir/$fname  #ASCII and HTML were both once created.
output_file=$inventory_dir/$fname.html
temp_file=$temp_dir/$fname$$.temp

#Remove the temporary file on failure.
trap "rm -f $temp_file; exit 1" HUP INT QUIT ABRT ALRM TERM

#If we write to a temp file, and swap in it when we are done, there will
# not any time when the page is empty becuase the scipt is still writing
# the file.
rm -f $temp_file $old_output_file

#Make sure we know how up-to-date this is.
echo -e Cloning Report: `date` > $temp_file 2>&1
echo -e Brought to You by: `basename $0` "\n" >> $temp_file 2>&1


echo                   >> $temp_file 2>&1
echo "===============" >> $temp_file 2>&1
echo "Cloning per Day" >> $temp_file 2>&1
echo "===============" >> $temp_file 2>&1
echo                   >> $temp_file 2>&1

echo "Creating Cloning per Day" `date`

cloning_per_day >> $temp_file 2>&1

echo                     >> $temp_file 2>&1
echo "===============" >> $temp_file 2>&1
echo "Cloning History" >> $temp_file 2>&1
echo "===============" >> $temp_file 2>&1
echo                     >> $temp_file 2>&1

echo "Creating Cloning History" `date`

cloning_history >> $temp_file 2>&1


#Turn out the html page.
make_html "$tl_name Cloning Summary Page" $temp_file $output_file $url_dir

#Remove the temp file.
rm -f $temp_file
