#!/bin/sh
OUT=ChangeLog
BASE=http://etoys.squeak.org/updates
VERSION=etoys4.1
FETCH="curl -s -S"
#FETCH="wget -q -O -"
UPDATES=`$FETCH $BASE/updates.list \
	| tr '\r' '\n' \
	| awk "/^#/{p=0};{if(p)print};/^#$VERSION/{p=1}" \
	| tac \
	`
mkdir -p updates
mv -f  $OUT $OUT~

COUNT=`echo $UPDATES|wc -w`

for f in $UPDATES ; do
	N=$(($N+1))
	printf "[$N/$COUNT] $f                              \r"
	
	[ -f updates/$f ] || $FETCH $BASE/$f > updates/$f
	
	echo >> $OUT
	echo === $f ===  >> $OUT
	cat updates/$f \
	| tr '\r' '\n' \
	| awk '/"/{if(p){print;exit}};/^"/{p=1};{if(p)print};/\!/{c=c+1;if(c>1)exit;if(p){print;exit}}' \
	| sed 's/"//g;s/!//g' \
	>> $OUT
done

printf "\n"
