#not yet used.
MAJ=5.6
VER=5.6.48
REL=1

CWD=`pwd`

#https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-linux-glibc2.12-x86_64.tar.gz
#https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-community-server-5.7.20-1.el6.x86_64.rpm

WGET_OPTION=--no-check-certificate

#must alrady be cd to the current folder to be saved to.
. ./get_file.sh

grab()
{
	OS=$1
	BIT=$2
	RPM_LIST=${3}.txt

	#https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.20-1.el6.${BIT}.rpm-bundle.tar
	#https://cdn.mysql.com/Downloads/MySQL-5.7/mysql-5.7.20-1.el6.${BIT}.rpm-bundle.tar.md5

	#https://dev.mysql.com/get/Downloads/MySQL-5.6/MySQL-5.6.38-1.el6.x86_64.rpm-bundle.tar

	F=mysql-${VER}-${REL}.${OS}.${BIT}.rpm-bundle.tar

	U=https://dev.mysql.com/get/Downloads/MySQL-${MAJ}/$F
	O=$F
	M=https://cdn.mysql.com/Downloads/MySQL-${MAJ}/$F.md5

	#wget $WGET_OPTION -O 64-bit/${MAJ}/$VER/$F https://dev.mysql.com/get/Downloads/MySQL-${MAJ}/$F
	get_file $U $O $M

	#if md5 and md5 failed, it wouldn't get this far.

	tar xvf $O --no-same-owner

	ls *${OS}.${BIT}.rpm > ${RPM_LIST}

	rm -f $O $O.md5
}

doDebian()
{
        cd ${CWD}/${MAJ}/${VER}/64-bit
        F=mysql-${VER}-linux-glibc2.12-x86_64.tar.gz
        U=https://dev.mysql.com/get/Downloads/MySQL-${MAJ}/$F
        M=https://cdn.mysql.com//Downloads/MySQL-${MAJ}/$F.md5
        O=$F
        get_file $U $O $M

        cd $CWD/debian/64-bit
        ln -s ../../${MAJ}/${VER}/64-bit/$F
}




doMain()
{
	cd ${CWD}/${MAJ}/${VER}/64-bit
	grab el6 x86_64 centos6-64
	grab el7 x86_64 centos7-64

	cd ${CWD}/${MAJ}/${VER}/32-bit
	grab el6 i686 centos6-32
}

mkdir -p ${MAJ}/${VER}/32-bit
mkdir -p ${MAJ}/${VER}/64-bit

doMain

#There were no tar.gz files for debian for 5.6, but are now
doDebian

cd $CWD/${MAJ}/$VER
#http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.8.tar.gz/from/http://mysql.mirror.rafal.ca/
#https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.20.tar.gz.md5
F=mysql-${VER}.tar.gz
U=https://dev.mysql.com/get/Downloads/MySQL-${MAJ}/$F
O=$F
M=https://cdn.mysql.com//Downloads/MySQL-${MAJ}/${F}.md5

#wget $WGET_OPTION -O mysql-${VER}.tar.gz http://dev.mysql.com/get/Downloads/MySQL-${MAJ}/mysql-${VER}.tar.gz/from/${FROM_SERVER}
get_file $U $O $M

cd $CWD
ln -sf ${MAJ}/${VER}/mysql-${VER}.tar.gz .

#to keep it backwards compat, for now:
rm -f ./${VER}
rm -f ./64-bit/${VER}
ln -sf ${MAJ}/${VER}/32-bit ./${VER}
ln -sf ../${MAJ}/${VER}/64-bit ./64-bit/${VER}

exit 0;

