#!/bin/bash
# Wrapper for SiteMap Generation Tools
# Created for use in a Cron Job
# Copyright Ben Tasker 2009 
# Released under the GNU GPL
# See http://benscomputer.no-ip.org/LICENSE for details

# Set your variables here


# If you haven't installed a scrip listed below, leave the variable blank and we'll skip that phase

# Where is the HTML Generation Script?
HTMLDIR=
# Where is the URLLIST Generation Script?
URLDIR=

# These three need each other!
# Where is the Google Sitemap Generation Script?
GOOGLEDIR=
# Where is the Configuration file for the Google Generation Script
GOOGLECONF=
# Where did you create the ping script (include the filename in this one)?
PINGSCRIPT=

# What command do you use to call python? Leaving this blank works fine on my system
PYTHONBIN=



# Code Begins

if [ "$1" == "-h" ]
then
clear
echo "Sitemap Generation Wrapper V0.1"
echo ""
echo ""
echo "Usage of this script is simple, to enable logging call the script with a path to a file as the only argument"
echo "example sitemap_wrapper.sh /var/log/sitemaps.log"
echo "Otherwise call without arguments"
exit
fi


if [ "$1" == "" ]
then
# Logging is turned off
OUTPUT="/dev/null"
else
OUTPUT="$1"
fi

echo "Program Started" > $OUTPUT

if [ "$URLDIR" == "" ]
then
# URLLIST Generation not installed
echo "Not Generating URL List" >> "$OUTPUT"
else
"$URLDIR"/URL_List_gen.sh >> "$OUTPUT"
fi

if [ "$HTMLDIR" == "" ]
then
# We've not been told where the HTML Generation Script is, skip this bit
echo "Not Generating HTML" >> "$OUTPUT"
else
"$HTMLDIR"/HTML_gen.sh >> "$OUTPUT"
fi

if [ "$GOOGLEDIR" == "" ]
then
# Google Sitemap Generation Not INstalled
echo "Not Generating Google Sitemap" >> "$OUTPUT"
else
if [ "$GOOGLECONF" == "" ]
then
# User didn't specify a configuration file, we need it!!!!!!!!
echo "Google Configuration file not specified, exiting!!!" >> $OUTPUT
echo "Google Configuration file not specified, exiting!!!"
fi
$PYTHONBIN "$GOOGLEDIR"/sitemap_gen.py --config=$GOOGLECONF --testing >> "$OUTPUT"

if [ "$PINGSCRIPT" == "" ]
then
# User doesn't want to use the Ping Script, or has not created it.
echo "Ping Script Unavailable" >> "$OUTPUT"
else
$PINGSCRIPT >> "$OUTPUT"


fi
fi
exit




