#!/bin/bash

REPO="/disk/github/active/Melawy/melawy-repo/x86_64/"

echo -n $( dirname -- "$( readlink -f -- "$0" )" ) > pwd.txt

CWD=$(cat pwd.txt)

for package_dir in $(find . -mindepth 1 -maxdepth 2 -type d)
do
    cd $CWD/$package_dir
    if [[ -f "PKGBUILD" ]]; then
        makepkg --syncdeps --asdeps --needed --noconfirm --clean --cleanbuild --force
        package_file=$(ls -1 | grep ".zst")
        cp -v $CWD/$package_dir/$package_file $REPO/
    fi
    cd $CWD
done
