#! /bin/sh

# $Id: duplication_summary,v 1.9 2009/07/29 14:36:21 zalokar Exp $

#Dump the duplication information.

#Get all the common stuff for migration, duplication and cloning reporting.
source migration_common

#Create the variables that point to the files to output to.
fname=DUPLICATION_SUMMARY
output_file=$inventory_dir/$fname
temp_file=$temp_dir/$fname.temp

#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

#Make sure we know how up-to-date this is.
echo -e Duplication 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 "Duplication Summary" >> $temp_file 2>&1
echo "===================" >> $temp_file 2>&1
echo                       >> $temp_file 2>&1

echo "Creating Duplication Summary" `date`

echo "In the following table:" >> $temp_file 2>&1
echo "migration_closed_not_shelved + migration_closed_shelved + duplication_closed_not_shelved + duplication_closed_shelved + remaining_to_scan_and_close + blank_volumes = total" >> $temp_file 2>&1

summary >> $temp_file 2>&1

echo >> $temp_file 2>&1
echo >> $temp_file 2>&1

echo "The volumes counted in the following table are also included in the previous table." >> $temp_file 2>&1

summary_skipped_bad_files >> $temp_file 2>&1

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

echo "Creating Duplication per Day" `date`

duplication_per_day >> $temp_file 2>&1

echo                                   >> $temp_file 2>&1
echo "===============================" >> $temp_file 2>&1
echo "Duplication/Migration Remaining" >> $temp_file 2>&1
echo "===============================" >> $temp_file 2>&1
echo                                   >> $temp_file 2>&1

echo "Creating Duplication/Migration Remaining" `date`

volumes_remaining >> $temp_file 2>&1

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

echo "Creating Duplication History" `date`

duplication_history >> $temp_file 2>&1


mv "$temp_file" "$output_file" #Do the temp file swap.

#For backward compatiblity make an html file too.
echo Starting to making html file for duplication.
rm -f $output_file.html
cat << EOF >> $output_file.html
<html> <head> <title>$tl_name Duplication Summary Page</title> </head>
<body>
<body bgcolor="#ffffff" text=#a0a0ff">
<meta http-equiv="Refresh" content="900">
<hr>
<pre>
EOF

    #We need to add a link to the web page with the plots on it.
    link="<a href=$url_dir/migration_summary/plot_enstore_system.html>Migration Summary Plots</a>"

    #The following sed is used more like cat to append $output_file
    # to $output_file.html.  The fancy sed part just inserts the link
    # on line 3 in the process of "cat"ing the file.
    sed "3s;\(.*\);${link}\n\1;" $output_file >> $output_file.html

    echo >> $output_file.html
    echo ${link} >> $output_file.html
    echo >> $output_file.html

    cat << EOF >> $output_file.html
</pre>
<hr>
<hr>
</body>
EOF
