#! /bin/bash
#
# Copyright © 2010 Igalia S.L.
#
# Adrian Perez <aperez@igalia.com>
#
# Distributed under terms of the GPLv3 license:
# http://www.gnu.org/licenses/gpl-3.0.html

##############################################################
#                                                            #
#  This searches all .deb packages and Sphinx-generated      #
#  documentation, and copies the files in the destination    #
#  directory specified in the command line. The resulting    #
#  directory is suitable for use with the file upload build  #
#  steps of Buildbot.                                        #
#                                                            #
##############################################################

if ! [ "$1" ] ; then
	echo "$(dirname "$0"): No destination path given!"
	echo "Usage: $(dirname "$0") directory-path"
	exit 1
fi >&2

mkdir -p "$1/debs"
mkdir -p "$1/doc"

echo "*** Packages:"
while read -r line ; do
	ln -v -f "${line}" "$1/debs"
done < <( find .. -name '*.deb' )

echo "*** Documentation:"
for dir in tools/*-admin ; do
	if [ -r "${dir}/build/sphinx/html/index.html" ] ; then
		echo "=== Copying documenation '${dir}/build/sphinx/html'"
		tdir=${dir#tools/}
		mkdir -p "$1/doc/${tdir}"
		cp -r "${dir}/build/sphinx/html"/* "$1/doc/${tdir}/"
	else
		echo "=== No documentation in '${dir}/build/sphinx/html', skippping."
	fi
done

