#!/bin/sh
shout() { echo "$0: $@" >&2; }
barf() { shout "fatal: $@"; exit 111; }
safe() { "$@" || barf "cannot $@"; }

me=`cat package/path | cut -d'/' -f2`
unix=`uname -a | cut -d' ' -f1 | tr [a-z] [A-Z]`
rcdir=""

if [ -f conf-home ]
then
  rcdir=`head -1 conf-home`
  if [ -d "${rcdir}" ]
  then
    shout "Deploying ezmlmrc in: ${rcdir}."
  else
    if [ ! -d ${rcdir} ]
    then
      barf "'${rcdir}' not available; check conf-home."
    fi
  fi
else 
	barf "can't determine ezmlmrc deploy directory."
	exit 1
fi

cd ezmlmrc

if [ -z $1 ]
then 
  shout "Setting 'ezmlmrc' language template to English (en)."
else
  lang=`ls -1 | grep ^$1`
  if [ `echo "${lang}" | wc -l` -eq 2 ] 
  then
    lang=$1
    shout "Setting language template to '${lang}'."
  else
    barf "could not determine ezmlmrc language template for language '$1'."
  fi
fi
    
safe make ${lang}
safe cp ezmlmrc ${rcdir}/

if [ -d ../compile ]
then
		safe cp -r ezmlmrc ../compile 
		shout "Copying 'ezmlmrc' into 'compile' dir for testing purpose."
fi

cd ..

exit 0
