#!/bin/sh

#
# Script to generate distribution builds of pLog
#
# (c) 27-08-2004, the pLog Team
#
#
# Requires two parameters: the name of the output package and the
# CVS tag label that will be used to fetch the contents of the build. Therefore,
# contents must be tagged _before_ running this script. 
# The same CVS label must be used for both the plog_devel and plog_docs module.
#

#
# server and repository path
#
SVNSERVER=http://devel.plogworld.net
SVNREPO=/svn/plog/plugins

#
# array with the files that we are going to remove before
# making the package... Wildcards, complete paths, whatever
# can be used here
#
TOREMOVE="unported/"
WORKFOLDER="/tmp/"

#
# helper functions to print things in different colors
#
NOCOLOR='\e[0m'
message()
{
 echo -e "\033[01;32m$*$NOCOLOR"
}

warning()
{
 echo -e "\033[01;33m$*$NOCOLOR"
}

error()
{
 echo -e "\033[01;31m$*$NOCOLOR"
}

# check parameters
if [ $# -lt 1 ]; then
    echo "Makes a zip package of a given plugin"
    echo ""
	echo "Usage: build.sh template"
	echo ""
	echo "Use 'all' in order to generate a package of all the template sets"
	exit -1
fi

# get the name of the template that we're trying to build
TEMPLATENAME=$1

# a temporary working folder like any other...
TMPFOLDER=${WORKFOLDER}`date | md5`
CURFOLDER=`pwd`

# export the current folder
message "Exporting folder..."
svn export . $TMPFOLDER

# remove whatever we don't need
message "Removing unnecessary files...";
for i in ${TOREMOVE}
do
  message "  -- removing $i"
  rm -rf ${TMPFOLDER}/$i
done

# build the correct template package, or all of them if that's what we were requested to do...
cd $TMPFOLDER
message "Creating ZIP package..."
if [ $TEMPLATENAME == "all" ]; then
    zip -r ${CURFOLDER}/_all_plugins.zip
    TEMPLATENAME=_all_plugins
else
    zip -r ${CURFOLDER}/${TEMPLATENAME}.zip ${TEMPLATENAME}/
fi

# upload the package -- works with OS X's ftp client... no guarantee about Linux!
ftp -a -u ftp://upload.sourceforge.net/incoming/${TEMPLATENAME}.zip ${TEMPLATENAME}.zip

message "Done!"

# cleanup
rm -rf $TMPFOLDER
