#!/bin/bash

if [ $# -lt 1 ]
then
    echo "Usage: `basename ${0}` version"
    exit
fi

export Version=${1}
: ${Product?"Product not specified"}
: ${AppcastName?"Appcast name not specified"}
: ${ProductURLUploadBase?"Product URL upload base not specified"}
: ${AppcastPath?"Appcast Path not specified"}

#
# Make sure the appcast stuff is all set up
#
grep ${Version} ${AppcastPath}/${AppcastName}.toc
if [ ${?} -ne 0 ]
then
    echo "Product version ${Version} is not in the appcast TOC."
    exit ${?}
fi

if [ ! -e ${AppcastPath}/${Product}-${Version}.mkd ]
then
    echo "Could not find entry for the release notes."
    exit 1
fi
if [ ! -e ${AppcastPath}/${Product}-${Version}.txt ]
then
    echo "No entry for version ${Version} in the appcast."
    exit 1
fi

#
# Build the appcast
#
pushd ${AppcastPath}
./mkappcast ${AppcastName}
./mkrelnotes ${AppcastName}
popd

#
# Now, actually push the results out to the server
#
scp ${AppcastPath}/${AppcastName}.xml ${ProductURLUploadBase}/
scp ${AppcastPath}/${AppcastName}-relnotes.html ${ProductURLUploadBase}/