MAJ=10.2
VER=10.2.32
REL=1
TYPE=linux2.6

RPM_OS=centos6

#http://mariadb.mirror.iweb.com/mariadb-5.5.38/source/mariadb-5.5.38.tar.gz
#http://mariadb.mirror.iweb.com/mariadb-5.5.38/yum/centos6-x86/rpms/
#http://mariadb.mirror.iweb.com/mariadb-5.5.38/yum/centos6-amd64/rpms/
#http://mirrors.accretive-networks.net/mariadb/mariadb-10.1.8/

#FROM_SERVER=http://mirror.csclub.uwaterloo.ca/mysql/
#FROM_SERVER=http://mirrors.accretive-networks.net/mariadb/mariadb-${VER}/
#FROM_SERVER=http://mariadb.mirror.iweb.com/mariadb-${VER}
#FROM_SERVER=http://mariadb.mirror.rafal.ca/mariadb-${VER}
#FROM_SERVER=http://ca.mirror.babylon.network/mariadb/mariadb-${VER}
#FROM_SERVER=http://mariadb.mirror.anstey.ca/mariadb-${VER}
FROM_SERVER=http://mariadb.mirror.iweb.com/mariadb-${VER}

. ./includes/ensure.sh

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

	#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 [ "${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}
	if [ "$2" != "" ]; then
		DEB_DIR=linux-$2
	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/mariadb-${VER}-${DEB_ARCH}.tar.gz ${FROM_SERVER}/bintar-${DEB_DIR}/mariadb-${VER}-${DEB_ARCH}.tar.gz

	ensure $VER/mariadb-${VER}-${DEB_ARCH}.tar.gz
}

doMain()
{
        echo -n "" > ${VER}/centos6-32.txt
        echo -n "" > ${VER}/centos6-64.txt
        echo -n "" > ${VER}/centos7-64.txt
	#echo -n "" > ${VER}/centos8-64.txt

        for i in server client devel shared common compat backup; do
        {
                echo "getting $i ...";
                grab $i centos6 centos6 centos6-32
                grab64 $i centos6 el6 centos6-64 type-first

		#http://mariadb.mirror.iweb.com/mariadb-10.2.23/yum/centos74-amd64/rpms/MariaDB-server-10.2.23-1.el7.centos.x86_64.rpm
		grab64 $i centos73 el7.centos centos7-64 type-first
		#grab64 $i centos73 centos73 centos7-64

		#grab64 $i centos8 el8 centos7-64 type-first
        };
        done;
}

doAllDebian()
{
	#mariadb-10.0.17-linux-glibc_214-i686.tar.gz
	#http://mariadb.mirror.iweb.com/mariadb-10.0.17/bintar-linux-glibc_214-x86/mariadb-10.0.17-linux-glibc_214-i686.tar.gz
	#mariadb-10.0.17-linux-glibc_214-x86_64.tar.gz
	#mariadb-10.0.17-linux-x86_64.tar.gz
	#mariadb-10.0.17-linux-i686.tar.gz
	#http://mariadb.mirror.iweb.com/mariadb-10.0.17/bintar-linux-x86/mariadb-10.0.17-linux-i686.tar.gz

#	doDebian glibc_214-i686 glibc_214-x86
	doDebian glibc_214-x86_64
	doDebian x86_64
#	doDebian i686 x86
}

mkdir -p $MAJ
cd $MAJ
CWD=`pwd`
mkdir -p $VER

	doMain

	cd $CWD
	doAllDebian

	cd $CWD
	wget -O ${VER}/mariadb-${VER}.tar.gz ${FROM_SERVER}/source/mariadb-${VER}.tar.gz

	ensure ${VER}/mariadb-${VER}.tar.gz

exit 0;

