#not yet used.
MAJ=8.0
VER=8.0.20
REL=1
#TYPE=linux_glibc2.5

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
	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()
{
	#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-5.7.20-linux-glibc2.12-i686.tar.gz

	BIT=$1

	F=mysql-${VER}-linux-glibc2.12-${BIT}.tar.xz
	U=https://dev.mysql.com/get/Downloads/MySQL-${MAJ}/${F}
	O=$F
	M=

	get_file $U $O $M
}

doFreeBSD()
{
	#mysql-5.7.24-freebsd11-x86_64.tar.gz
	#https://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.24-freebsd11-x86_64.tar.gz
	BIT=$1
	F=mysql-${VER}-freebsd12-${BIT}.tar.gz
	U=https://dev.mysql.com/get/Downloads/MySQL-${MAJ}/${F}
	O=$F
	M=

	get_file $U $O $M
}

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

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

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

#rpms
doMain

#64-bit debian/freebsd
cd ${CWD}/${MAJ}/${VER}/64-bit
doDebian x86_64
doFreeBSD x86_64

#32-bit debian
#cd ${CWD}/${MAJ}/${VER}/32-bit
#doDebian i686


#connector
#https://dev.mysql.com/doc/dev/connector-cpp/8.0/
F=mysql-connector-c++-${VER}-linux-glibc2.12-x86-64bit.tar.gz
wget -O $CWD/${MAJ}/${VER}/64-bit/${F} https://dev.mysql.com/get/Downloads/Connector-C++/${F}

#source
cd $CWD/${MAJ}/$VER
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
get_file $U $O $M

cd $CWD

exit 0;

