#!/bin/bash

# Copyright 2009-2020 Holger Levsen (holger@layer-acht.org)
# 
# 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 2 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, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

#
# send reminders about the status of the package
# run via cron by holger on paradis.debian.org
#
#   holger@paradis:~$ crontab -l
#   # m h  dom mon dow   command
#   # run on the 2nd and 4th sunday of a month
#   23 1 8-14 * * test `/bin/date +\%w` -eq 0 && /home/holger/debian-edu-doc/debian/mail_stats_to_list
#   23 1 22-28 * * test `/bin/date +\%w` -eq 0 && /home/holger/debian-edu-doc/debian/mail_stats_to_list all

export PATH="/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games"
set -x
cd ~holger/debian-edu-doc
git pull > /dev/null 2>&1 && git status 2>&1
RESULT=$?
if [ $RESULT -ne 0 ] ; then
	echo "Problem with git clone (status '$RESULT') at paradis.debian.org:~holger/debian-edu-doc - please fix." | mail -s "problem with debian-edu-doc status mails" holger@layer-acht.org
	exit 1
fi

#
# loop through some manuals
#
cd documentation
if [ "$1" = "all" ] ; then
	MANUALS="debian-edu-bullseye debian-edu-buster"
else
	MANUALS="debian-edu-bullseye"
fi
for i in $MANUALS ; do
	if [ $(ls $i/$i-manual.*.po > /dev/null 2>&1 ; echo $?) -eq 0 ] ; then
		cd $i 
		TMPFILE=$(mktemp)
		echo "The (translated) $i manual in PDF, ePUB or HTML formats are available at https://jenkins.debian.net/userContent/debian-edu-doc//" > $TMPFILE
		echo >> $TMPFILE
		echo "To understand this mail better, please read /usr/share/doc/debian-edu-doc/README." >> $TMPFILE
		echo "This mail is automatically send by a cronjob run by Holger Levsen every two weeks. Please send feedback, suggestions, flames and cookies via this list." >> $TMPFILE
		echo >> $TMPFILE
		make update > /dev/null 2>&1 
		make status >> $TMPFILE 2>&1 
		cat $TMPFILE | mail -s "Content and translation status for the $i manual" debian-edu@lists.debian.org
		rm $TMPFILE
		cd ..
	fi
done
cd ..

make clean
git reset --hard

