#!/bin/sh

START_DIR=`pwd`
export PGROUP=$1
shift
while [ "$1" ]; do
  echo Building $1
  if [ -d $PGROUP/$1 ]; then
    cd $PGROUP/$1
    ./VBuild
    if [ ! $? = 0 ]; then
      echo "ERROR: buildpkg failed."
      exit 1
    fi
  elif [ -f $PKG_DIR/$PGROUP/$1*.tgz ]; then
    if [ "$INSTALL_PKG" = "yes" ]; then
       echo Installing package $PKG_DIR/$PGROUP/$1
       installpkg $PKG_DIR/$PGROUP/$1*.tgz
    else
       echo "ERROR: Could not install $1. Aborting"
       exit 1
    fi       
  else
    echo WARNING: Could not find $PGROUP/$1 tarbal nor package
  fi
  cd $START_DIR
  shift
done
unset START_DIR
