#!/bin/sh

###############################################################################
# Name:        makepackages.sh
# Purpose:     Create sample packages
# Author:      Francesco Montorsi
# Licence:     wxWindows licence
# RCS-ID:      $Id: makepackages.sh,v 1.11 2007/02/01 11:56:00 frm Exp $
###############################################################################

echo
echo "Creating packages..."

# DO NOT REMOVE OLD PACKAGES:
#       rm -f *.wxz *.tar.gz *.zip
# wxp will overwrite them safely and doing a such 'rm' is undesired when
# you want to include in the wxWPM repo other packages from 3rd parties

for p in `find . -name "*.wxp"`; do
    echo    "  => Making a package for `echo $p | cut -d '/' -f 2`"
    echo -n "     "
    wxp pack $p
    echo
done


# you must have WXP installed system-wide for the following step to work:

packages=`ls *.zip *.tar.gz *.wxz 2>/dev/null`

echo "Creating WXL repository..."
wxp create-repo packages.wxl $packages

echo "Creating the repository summary and details HTML pages..."
wxp output-html website summary $packages >repo_summary.inc.html
wxp output-html website details $packages >repo_details.inc.html

# now put the details for each package in separed pages:
for p in $packages; do
    name=`wxp get-info name $p`
    wxp output-html website details $p >"$name"_details.inc.html
done


# this works only if you have the wxWPMWebsite module placed next to the wxWPM
# module in your filesystem:

websiteRepoFolder="../../wxWPMWebsite/packages"
websiteHtmlRepoFolder="../../wxWPMWebsite/packages-html"

echo "Copying WXL, packages and summary/details pages to '$websiteRepoFolder'..."

if [ -d "$websiteRepoFolder" -a -d "$websiteRepoFolder" ]; then

    cp $packages packages.wxl "$websiteRepoFolder"
    mv *.inc.html "$websiteHtmlRepoFolder"

    if [ -d "$websiteHtmlRepoFolder/logo" ]; then
        # heuristic search of package logo files:
        logos=`find . -name *.gif -o -name *.png -o -name *.jpg | grep logo`
        cp $logos "$websiteHtmlRepoFolder/logo"
    fi

    if [ -d "$websiteHtmlRepoFolder/screenshot" ]; then
        # heuristic search of package screenshot files:
        screens=`find . -name *.gif -o -name *.png -o -name *.jpg | grep screen`
        cp $screens "$websiteHtmlRepoFolder/screenshot"
    fi

else

    echo "  No '$websiteRepoFolder' and/or '$websiteHtmlRepoFolder' folder... cannot proceed"
fi


# upload the packages to the wxWPM website

repoURL="/home/groups/w/wx/wxwpm/htdocs/packages"
dest="`whoami`@shell.sourceforge.net:$repoURL"

echo
echo -n "  Do you want to upload the packages (y/n) ?"
read reply
if [ "$reply" = "y" ]; then
   echo "Secure copying the packages to '$dest'..."
   scp $packages $dest
fi

echo "All operations completed."
echo
