#!/bin/bash
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#

set -e
if [ ! $1 ]
then
	echo "Usage: $0 <output-dir> <xml-file>"
	echo
	echo "Convert a pilot-qof address XML file into simple vcards"
	echo "Two arguments needed, output directory and the XML file"
	exit
fi
if [ ! -d $1 ]
then
	echo "First argument should be a directory to write the vcards"
	exit
fi
if [ ! -f $2 ] && [ '-' != $2 ]
then
	echo "Second argument should be an XML file or '-' for stdin."
	exit
fi

XML_CATALOG_FILES="/opt/holly/pilot-qof/share/xml/datafreedom/xsl/catalog.xml" \
 xsltproc --nonet -o $1 http://www.data-freedom.org/xsl/pilot-qof-address-vcard1.xsl $2

