#! /bin/sh

set -e

cd $(dirname $0)

PODMAN=docker

build_constainer() {
    $PODMAN build -t reprepro .
}

reprepro() {
    $PODMAN run --rm -it --privileged \
	    -v ${HOME}/.gnupg:/root/.gnupg \
	    -v $(pwd)/..:/work -w /work/debian reprepro reprepro $@
}

update_unstable() {
    packages=$(find ../development -type f -name evebox\*.deb)
    reprepro -b . remove unstable evebox
    for deb in ${packages}; do
        echo "Adding ${deb} to unstable."
        reprepro -b . includedeb unstable ${deb}
    done
}

update_stable() {
    packages=$(find ../release/latest/ -type f -name \*.deb)
    for deb in ${packages}; do
        echo "Adding ${deb} to stable."
        reprepro -b . includedeb stable ${deb}
    done
}

usage() {
    echo "$0 [stable|unstable]"
    exit 1
}

case "$1" in
    "unstable")
        build_constainer
        update_unstable
        ;;
    "stable")
        build_constainer
        update_stable
        ;;
    *)
        usage
        exit 1
        ;;
esac

#update_unstable
#restorecon -RvF $(pwd) > /dev/null
