# Exit on error:
set -e

PKGLIST=`grep -v '#' meta-$@.txt`

for PKG in $PKGLIST;
do {
    echo  0. Putting PKGNAME in /tmp/meta.txt...
    echo $PKG >> /tmp/meta.txt

    echo  1. Creating pkgusr for $PKG...
    add_package_user $PKG $PKG 10000 20000 $PKG 10000 20000

    echo  2. Getting recipe from /src/recipes...
    cp /src/recipes-1.6/$PKG /src/$PKG/build-$PKG.sh

    echo  3. Removing build-me.sh...
    rm /src/$PKG/build-me.sh

    echo  4. Changing ownership of the recipe...
    chown $PKG:$PKG /src/$PKG/build-$PKG.sh

    echo  5. Make the recipe executable...
    chmod u+x /src/$PKG/build-$PKG.sh

    echo  6. Building the recipe as pkgusr...
    su - $PKG -c ./build-$PKG.sh
};
done;

exit 0
