#!/bin/sh

ARCH=
DIR=
FILE=

usage()
{
  echo "Usage: `basename $0` -a <arch> -f <inputfile> [-d <outputdir>]"
  exit 255
}

while getopts a:d:f: ARG ; do
  case $ARG in
    a)
      ARCH=$OPTARG
      ;;
    d)
      DIR=$OPTARG
      ;;
    f)
      FILE=$OPTARG
      ;;
    \?)
      usage
      ;;
  esac
done

if [ -z "$ARCH" -o -z "$FILE" ] ; then
  usage
fi

if [ ! -f $FILE ] ; then
  echo "File $FILE not found!"
  exit 1
fi

if [ -z "$DIR" ]; then
  xsltproc --stringparam arch $ARCH /usr/share/repoml/repoml.xsl $FILE
else
  xsltproc --stringparam arch $ARCH --stringparam dir $DIR /usr/share/repoml/repoml.xsl $FILE
fi
