#! /bin/sh

umask 022
export PATH='/bin:/usr/bin:/usr/local/bin'

if [ ! -d $HOME/diet-pc/ipkg-tree ]; then
    cat 1>&2 <<EOF
$HOME/diet-pc/ipkg-tree is missing - must run "dpc-unpack" first!
EOF
    exit 1
fi

cd $HOME/diet-pc
for PKG in ipkg-tree/*; do
    [ $PKG = 'ipkg-tree/*' ] && break
    ARCH=`grep -s '^Architecture: ' $PKG/CONTROL/control | cut -f2 -d' '`
    [ ! "$ARCH" ] && continue
    mkdir -p $ARCH
    sudo ipkg-build -o root -g root $PKG $PWD/$ARCH
done
exit 0
