#!/bin/sh
#
# http://www.pdaXrom.org 2004
# package installer
# ipkg-install package1[ package2[.. packageN]]
#

PREFIX=$1
shift

for PACKAGE in $* ; do
    if [ ! -f $PACKAGE ]; then
	ipkg -d $PREFIX -force-depends -force-defaults install $PACKAGE
	if [ "$?" = "1" ]; then
	    ipkg -d $PREFIX remove $PACKAGE
	fi
    else
	mkdir /tmp/ipkman.tmp.$$
	if zcat -dc $PACKAGE | tar -xOf - ./control.tar.gz | zcat -dc - | tar -xf - -C /tmp/ipkman.tmp.$$; then
	    PKG=`cat /tmp/ipkman.tmp.$$/control | grep 'Package:' | sed -e '/Package:/s///g'`
	    ipkg -d $PREFIX -force-depends -force-defaults install $PACKAGE
	else
	    echo "Corrupted or not package file!"
	fi
	rm -rf /tmp/ipkman.tmp.$$
    fi
done
