#!/bin/bash
# Publish results from one or more runs
#Parameters:
# $1 =  $nickname or
#	a fully qualified host and path with anonymous ftp access ex. "mysystem.us.ibm.com/pub/kernels/
#	ex1 my_results/myresultsdir  
#	ex2 mysystem.us.ibm.com/pub/kernels/myresultsdir
# $2 email address to send notification to ex. slpratt@austin.ibm.com (optional)

. /etc/autobench.conf || . functions

# $1=$host, $2=$remotepath
function ftp_subdir() {
for subfile in *
do
        echo processing dirent $subfile
        if [ -d $subfile ]
        then
            ftp_mkdir $1 "$2/$subfile"
            cd $subfile
            ftp_mput $host "*" "$2/$subfile"
            ftp_subdir $1 $2/$subfile
            cd ..
        fi
done
}

file=$1
host=`hostpath $file`
path=${file##$host} 

text="Results for automated run stored in the following directories:"

machinename=`hostname -s`
cd $AUTODIR/logs
for file in *
do
	if [ -d $file -a ${file:0:7} != "default" ]; then
      	    cp $LOGFILE $file
			cp $AUTODIR/logs/console_log $file
			cp $AUTODIR/logs/autobench.dat $file
       	    ftp_mkdir $host "$path/$machinename.$file"
       	    cd $file
       	    ftp_mput $host "*" "$path/$machinename.$file"
            ftp_subdir $host $path/$machinename.$file
            cd ..
            text="$text  http://$host$path/$machinename.$file"
	    tar -czf $machinename.$file.tar.gz $file
		mkdir -p $AUTODIR/archives
		mv $machinename.$file.tar.gz $AUTODIR/archives
	    rm -rf $file
        fi
done
if [ $# -gt 1 ]
then
	echo "$text" | mail -s "Benchmark results available"  $2
fi

cd $AUTODIR/scripts
