#!/bin/sh
# Generate an example source package from the template, by uncommenting all
# examples.
#
# Author: Martin Pitt <martin.pitt@ubuntu.com>
# Copyright: (C) 2011 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

set -e

top_srcdir=$(dirname $(dirname $(readlink -f $0)))
# support running from source tree
if [ -e "$top_srcdir/template/depends.txt" ]; then
    export UBUNTU_DEFAULTS_TEMPLATE_DIR="$top_srcdir/template"
    export DH_AUTOSCRIPTDIR="$top_srcdir/debhelper-scripts"
    "$top_srcdir"/bin/ubuntu-defaults-template ubuntu-defaults-test
else
    ubuntu-defaults-template ubuntu-defaults-test
fi

cd ubuntu-defaults-test

# uncomment all examples
find -name '*.txt' | xargs sed -i '/^# Example:/,$ { /^# Example/d; s/^# // }'
# stick in background
if [ -e "$top_srcdir/test/test.jpg" ]; then
    cp "$top_srcdir/test/test.jpg" desktop/background.jpg
else
    cp "$(dirname $(readlink -f $0))/test.jpg" desktop/background.jpg
fi

# build package
PATH="$top_srcdir/bin:$PATH" dpkg-buildpackage -d -us -uc
