#!/bin/sh

ensure()
{
        if [ ! -s $1 ]; then
                echo ""
                echo "*******************************"
                echo "Download of $1 is empty! Aborting everything"
                echo "*******************************"
                echo ""
                exit 1
        fi
}

grab()
{
        RPM_OS=$2
        RPM_OS_FILE=$3
        RPM_LIST=${VER}/${4}.txt
        F=MariaDB-${VER}-${RPM_OS_FILE}-i686-${1}.rpm

        if [ "${SKIP_FILLED}" = "1" ] && [ -s $VER/${F} ]; then
                echo "$VER/${F} has size. Skipping"
                return
        fi

        #http://mariadb.mirror.iweb.com/mariadb-5.5.38/yum/centos6-x86/rpms/MariaDB-5.5.38-centos6-i686-server.rpm
        wget -O $VER/${F} ${FROM_SERVER}/yum/${RPM_OS}-x86/rpms/${F}

        ensure $VER/${F}

        echo ${F} >> ${RPM_LIST}
}

grab64()
{
        RPM_OS=$2
        RPM_OS_FILE=$3
        RPM_LIST=${VER}/${4}.txt
        F=MariaDB-${VER}-${RPM_OS_FILE}-x86_64-${1}.rpm

        if [ "${SKIP_FILLED}" = "1" ] && [ -s $VER/${F} ]; then
                echo "$VER/${F} has size. Skipping"
                return
        fi

        if [ "${5}" = "type-first" ]; then
                #MariaDB-server-10.2.23-1.el7.centos.x86_64.rpm
                F=MariaDB-${i}-${VER}-${REL}.${RPM_OS_FILE}.x86_64.rpm
        fi

        wget -O $VER/${F} ${FROM_SERVER}/yum/${RPM_OS}-amd64/rpms/${F}

        ensure $VER/${F}

        echo ${F} >> ${RPM_LIST}
}

doDebian()
{
        DEB_ARCH=linux-$1
        DEB_DIR=${DEB_ARCH}
        F=mariadb-${VER}-${DEB_ARCH}.tar.gz
        if [ "$2" != "" ]; then
                DEB_DIR=linux-$2
        fi

        if [ "${SKIP_FILLED}" = "1" ] && [ -s $VER/${F} ]; then
                echo "$VER/${F} has size. Skipping"
                return
        fi

        #http://mariadb.mirror.iweb.com//mariadb-10.0.17/bintar-linux-glibc_214-x86_64/mariadb-10.0.17-linux-glibc_214-x86_64.tar.gz
        wget -O $VER/$F ${FROM_SERVER}/bintar-${DEB_DIR}/$F

        ensure $VER/$F
}

