#!/bin/bash
#This is used for retrieving the "template.pot files as htmls" and the pot files from dany's site (soon)

wgetOpts='--passive-ftp --dot-style=mega --continue -T 30 -e ftp_proxy=http://your.proxy.4ftp:port/ -e http_proxy=http://your.proxy.4http:port/ -Ulegalbrowser'

STATUSFILE=STATUS\.utf8\.txt
LANG=ro

STATUSLOC=http\:\/\/people\.debian\.org\/\~barbier\/d\-i\/l10n\/$LANG\/$STATUSFILE

POFILE=$LANG\\\.po

SITE=cvs\\\.alioth\\\.debian\\\.org\\\/cgi\\\-bin\\\/cvsweb\\\.cgi\\\/
SERVICE=http\\\:\\\/\\\/
SUFFIX=\\\?cvsroot\\\=d\\\-i

OUTPUT=downloadpaths\.in

#------------------------------------------

wget $wgetOpts "$STATUSLOC"

grep -e "^Missing" "$STATUSFILE" | sed s/"^Missing file: "// | sed s/^/"$SERVICE$SITE"/ | sed s/"$POFILE"/templates\.pot/| sed s/$/"$SUFFIX"/ > "$OUTPUT"


# the file looks like :
# http://cvs.alioth.debian.org/cgi-bin/cvsweb.cgi/debian-installer/partman/partman/debian/po/templates.pot?rev=1.10&content-type=text/x-cvsweb-markup&cvsroot=d-i

#now we need the dirs...otherwise the templates are overwritten

wget -x $wgetOpts `cat "$OUTPUT`

if test -f /bin/mktemp
then
	TMPFILE=`mktemp`
else
	TMPFILE=`date +%d%m%y%k%M%S`
	touch $TMPFILE
fi

#grep -A5 'Request diff between arbitrary revisions' `find . -name templates\.pot\*`| grep 'Revision' | sed s/A\>\ .*$/A\>/ | sed s/templates\.pot\@cvsroot\=d\-i\-\ Revision\ \<A\ HREF\=\"// > $TMPFILE

grep -A5 'Request diff between arbitrary revisions' `find . -name templates\.pot\*`| grep 'Revision' | sed s/A\>\ .*$/A\>/ | sed s/templates\.pot\@cvsroot\=d\-i\-\ Revision\ \<A\ HREF\=\"// | sed s/\"\>\<[bB]\>.*// | sed s/^\.\\\//"$SERVICE"/ | sed s/amp\;//g > $TMPFILE

#find . -name "templates\.pot\*" | grep -A5 'Request diff between arbitrary revisions' | grep 'Revision' > $TMPFILE

wget -x $wgetOpts `cat "$TMPFILE`

#this is really bold (loosing info), but I guess if is ok with you, then this is ok...
rm -f `find . -name templates\.pot\*`

if test -f /usr/bin/lynx
then 
	DUMPPER=lynx\ \-dump
else
	if test -f /usr/bin/links
	then
		DUMPPER=links\ \-dump
	else
		echo Dumpper to text not found. Leaving files html formatted
	fi
fi

#This is not yet complete...
#if test -n $DUMPPER
#then
#	#hmm, this might not work...
#	$DUMPPER `find . -name templates\.pot\*`
#
#	#OTOH, we could use the dumper for download dirrectly to text ;)
#	#we MUST set the proxy parameter according to the $SERVICE
#	$DUMPER -dump -http-proxy http://ns.siemensvdo.ro:81/ -ftp-proxy http://ns.siemensvdo.ro:81/ `cat $TMPFILE`
#fi

#We should brag about the place we're at ...
wget -x -r -l1 $wgetOpts 'http://people.debian.org/~barbier/d-i/l10n/POT/'
wget -x $wgetOpts 'http://people.debian.org/~barbier/d-i/l10n/rank.txt'

#rm -f $TMPFILE