#!/bin/bash

for dir in *
do
  echo
  echo $dir
  cd $dir
  if [ ! -f dead.package ]; then

    S=$(find . -maxdepth 1 ! -empty -name sources)
    if [ "$S" = "./sources" ]; then
      SPEC=$(find . -maxdepth 1 -name "*.spec")
      rpmbuild --clean --nodeps --define "_sourcedir ."  --define "_builddir ."  $SPEC
      # gfs-* is messy and leaves this crap around even after a clean
      rm -rf __MACOSX
      rm -rf ._GFS_ARTEMISIA ._GFS_BODONI_OT ._GFS_GAZIS
      cvs up
      make prep
    else
      echo "Empty or no sources."
      echo $S
    fi
  else
   echo "Dead package."
  fi
  cd ..
done
