#!/bin/bash

REPOSITORY=${REPOSITORY:-/tmp/slackware-aarch64-virtualization/virtualization-scripts}
CHECK=${CHECK:-0}
REFRESH=${REFRESH:-0}

export REPOSITORY CHECK REFRESH

for SLACKBUILD in \
    spice-protocol \
    spice \
    spice-gtk \
    gtk-vnc \
    lloyd-yajl \
    libvirt \
    libvirt-python \
    libvirt-glib \
    osinfo-db-tools \
    osinfo-db \
    libosinfo \
    virt-manager \
    libmd \
    libbsd \
    netcat-openbsd \
    qemu ;
do
    cd $REPOSITORY/$SLACKBUILD || exit 1
    f=$(basename $(cat download.info ))

    if [ ${CHECK} -eq "1" ]; then
      sha256sum -c $f.sha256 || exit 1
    fi

    if [ ${REFRESH} -eq "1" ]; then
      [[ -e $f ]] && rm -v $f*
      echo -e "\nDownloading source: $f\n"
      wget -c --progress=bar:force --timeout=30 --tries=5 -i download.info || exit 1

      [[ -e $f.sha256 ]] && rm $f.sha256 2>/dev/null
      sha256sum $f >> $f.sha256
      echo -e "Added SHA256 hash: $f.sha256\n\n"
    fi
done 

