#! /bin/sh
#
# Bad hack to hack on tinderbox.  Needs to be re-written in perl.
# Started by slamm@netscape.com, hacked a little by mcafee@netscape.com.
#
# usage: ./copydata <treeName>
#

tinderbox_link="http://tinderbox.mozilla.org"
bonsai_link="http://bonsai.mozilla.org"

if [ $# -lt 1 ]
then
  # Set $tree variable here..
  set -- SeaMonkey
fi 

tinderbox_dir=`pwd`
tree="SeaMonkey"

# Create new directories if they don't exist.

echo "Tree = " $tree

# tinderbox/$tree
if [ ! -d "$tree" ]
then
  echo "mkdir" $tree
  mkdir $tree
fi

# tinderbox/$tree/data
if [ ! -d "$tree/data" ]
then
  echo "mkdir" $tree/data
  mkdir $tree/data
fi

# tinderbox/data
if [ ! -d "data" ]
then
  echo "mkdir data"
  mkdir data
fi

# ../bonsai/data/$tree
if [ ! -d "../bonsai" ]
then
  echo "Need to pull ../bonsai from cvs."
  exit 1
fi

# ../bonsai/data
if [ ! -d "../bonsai/data" ]
then
  echo "mkdir -p ../bonsai/data"
  mkdir -p "../bonsai/data"
fi

# ../bonsai/data/$tree
if [ ! -d "../bonsai/data/$tree" ]
then
  echo "mkdir -p ../bonsai/data/"$tree
  mkdir -p ../bonsai/data/$tree
fi

# Copy tree data
for tree
do
  # Remove trailing slash
  tree=`expr $tree : "\([^/]*\)"`

  cd $tinderbox_dir/$tree
  
  for file in build.dat status.pl rules.pl sheriff.pl notes.txt treedata.pl who.dat ignorebuilds.pl scrapebuilds.pl scrape.dat
  do
    rm -f $file
    wget $tinderbox_link/$tree/$file
  done

  # Copy bonsai checkin batch data
  cd $tinderbox_dir/../bonsai/data/$tree
  if [ -f batchid.pl ]
  then
    rm -f batchid.pl batch-*.pl
  fi
  wget $bonsai_link/data/$tree/batchid.pl
  id=`cat batchid.pl | perl -pe 's/^.*?(\d+).*/$1/'` # stupid hack
  wget $bonsai_link/data/$tree/batch-$id.pl
done

cd $tinderbox_dir/data
rm -f imagelog.txt
wget $tinderbox_link/data/imagelog.txt

cd $tinderbox_dir
perl copylogs

