#!/bin/bash

# Copyright (c) 2004, 2005, 2006, 2007, 2008, 2009 by Miklos Vajna <vmiklos@frugalware.org>
# Copyright (c) 2007 by CSÉCSY László <boobaa@frugalware.org>
# genpkgdbs for Frugalware
# distributed under GPL License

# this script is invoked by cron daily

unset LC_ALL
# unsetting LANG breaks accents, but this is fine, keeping the possible
# localized outputs avoided
export LANG=en_US

. /usr/lib/frugalware/fwmakepkg

stabledir="../../frugalware-stable/t"

cd `dirname $0`/..

# Changelog
echo -n "generating ChangeLog.txt..."
stable=`git tag -l|grep '^[0-9]\+\.[0-9]$'|sed -n '$ p'`
if [ -n "$(git config i18n.logOutputEncoding)" ]; then
	git log $stable^.. | iconv -c -f $(git config i18n.logOutputEncoding) -t utf8 >ChangeLog.txt
else
	git log $stable^.. >ChangeLog.txt
fi
echo " done"

# AUTHORS
echo -n "generating AUTHORS..."
python tools/genauthors.py docs/xml/authors.xml AUTHORS
echo " done"

# Filelist.txt
echo -n "generating Filelist.txt..."
echo -e "Last Modified: `date`\n\nFrugalware Source Tree">Filelist.txt
tree|grep -v ^\.$>>Filelist.txt
echo " done"

# documentation

cd docs
make clean
make all 2>&1 |tee build.log
make -i all-i18n 2>&1 |tee build-i18n.log

# update pots

sudo -u vmiklos /pub/other/homepage-ng/autogen.sh --pot-only
sudo -u vmiklos /pub/other/setup/setup/autogen.sh --pot-only
sudo -u vmiklos /pub/other/fwlive/autogen.sh --pot-only
sudo -u vmiklos /pub/other/pacman-g2/pacman-g2/autogen.sh --gettext-only --pot-only
sudo -u vmiklos /pub/other/frugalwareutils/frugalwareutils/autogen.sh --pot-only
sudo -u priyank /pub/other/fw-control-center/fw-control-center/gnetconfig/autogen.sh --pot-only
sudo -u priyank /pub/other/fun/fun/autogen.sh --pot-only
sudo -u priyank /pub/other/fw-control-center/fw-control-center/gnetconfig-mcs-plugin/autogen.sh --pot-only
sudo -u priyank /pub/other/fw-control-center/fw-control-center/gfpm-mcs-plugin/autogen.sh --pot-only
sudo -u priyank /pub/other/gfpm/gfpm/autogen.sh --pot-only
sudo -u priyank /pub/other/gservice/gservice/autogen.sh --pot-only
sudo -u elentir /pub/other/fwife/fwife/autogen.sh --pot-only

# transfer them
ssh pootle sudo pootle-update /var/lib/pootle/po

# remove interim doc files
make cronclean

# testsuite
cd ../t
./srcjunk --remove >/dev/null 2>&1
(cd $stabledir; ./srcjunk --remove >/dev/null 2>&1)
./fpmjunk-i686 --remove >/dev/null 2>&1
(cd $stabledir; ./fpmjunk-i686 --remove >/dev/null 2>&1)
./fpmjunk-x86_64 --remove >/dev/null 2>&1
(cd $stabledir; ./fpmjunk-x86_64 --remove >/dev/null 2>&1)
./fpmjunk-arm --remove >/dev/null 2>&1
(cd $stabledir; ./fpmjunk-arm --remove >/dev/null 2>&1)
sh mailer.sh
# in case there would be leftover files
# XXX: this will remove important files if you run it as root..
rm -rf /tmp/tmp*

# autotag

cd ..
if date |grep -q ^Fri; then
	sh -c 'time dg optimize' &>tools/git-gc.log
fi
