#! /bin/sh

cd $(dirname $0)

docker build -t createrepo .

packages=$(find ../../release/latest/ -type f -name \*x86_64.rpm)
for rpm in ${packages}; do
    echo "Copying ${rpm} to $(pwd)/x86_64/"
    cp ${rpm} x86_64/
done

GPG_ID=5B90B643

for rpm in x86_64/*.rpm; do
    if ! rpm -Kv ${rpm} | grep -q Signature; then
        echo "Signing ${rpm}"
	docker run --rm -it --privileged \
	       -v /root/.gnupg:/root/.gnupg \
	       -v $(pwd):/work \
	       -w /work \
	       createrepo \
               rpm -D "_gpg_name ${GPG_ID}" --addsign "${rpm}"
    fi
done

docker run --rm -it --privileged \
       -v /root/.gnupg:/root/.gnupg \
       -v $(pwd):/work \
       -w /work \
       createrepo \
       createrepo x86_64
