#!/bin/sh

for i in *.ipk
do
	packagename=${i%%_*}
	#echo >&2 "$packagename..."
	GOOD=y
	for other in ${packagename}_*
	do
	    if [ $i != $other -a $other -nt $i ]
	    then
		GOOD=
		break
	    fi
	done
	if [ -n "$GOOD" ]
	then
#	    tar xfOz $i ./control.tar.gz | tar xfOz - ./control
	    # new version of ipkg uses ar instead of tar
	    ar pf $i control.tar.gz | tar xfOz - ./control
	    echo
	else
	    echo >&2 "Skipped old file: $i ($other is newer)"
	    #mv $i old
	fi
done >Packages