#!/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

## FIXME: need re-write
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"

# testsuite
cd t

./srcjunk --remove >/dev/null 2>&1
./srcmissing --download  >/dev/null 2>&1
./fpmjunk-x86_64 --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