#M_VER=10.1.25
#M_VER=10.3.18
#VER=25.3.27
#M_VER=10.4.11
M_VER=10.5.4
VER=26.4.5
REL=1


        #http://mariadb.mirror.iweb.com/mariadb-10.1.9/yum/centos5-x86/rpms/galera-25.3.9-1.rhel5.el5.i386.rpm
        #http://mariadb.mirror.iweb.com/mariadb-10.1.9/yum/centos5-amd64/rpms/galera-25.3.9-1.rhel5.el5.x86_64.rpm
        #http://mariadb.mirror.iweb.com/mariadb-10.1.9/yum/centos6-x86/rpms/galera-25.3.9-1.rhel6.el6.i686.rpm
        #http://mariadb.mirror.iweb.com/mariadb-10.1.9/yum/centos6-amd64/rpms/galera-25.3.9-1.rhel6.el6.x86_64.rpm
        #http://mariadb.mirror.iweb.com/mariadb-10.1.9/yum/centos7-amd64/rpms/galera-25.3.9-1.rhel7.el7.centos.x86_64.rpm

	#http://mariadb.mirror.iweb.com/mariadb-10.1.17/galera-25.3.17/bintar/
	#http://mariadb.mirror.iweb.com/mariadb-10.1.17/galera-25.3.17/bintar/galera-25.3.17-glibc_214-i686.tar.gz
	#http://mariadb.mirror.iweb.com/mariadb-10.1.17/galera-25.3.17/bintar/galera-25.3.17-glibc_214-x86_64.tar.gz
	#http://mariadb.mirror.iweb.com/mariadb-10.1.17/galera-25.3.17/bintar/galera-25.3.17-i686.tar.gz
	#http://mariadb.mirror.iweb.com/mariadb-10.1.17/galera-25.3.17/bintar/galera-25.3.17-x86_64.tar.gz

	#http://mariadb.mirror.iweb.com/mariadb-10.1.17/galera-25.3.17/src/
	#http://mariadb.mirror.iweb.com/mariadb-10.1.17/galera-25.3.17/src/galera-25.3.17.tar.gz


#FROM_SERVER=http://mirror.csclub.uwaterloo.ca/mysql/
FROM_SERVER=http://mariadb.mirror.iweb.com/mariadb-${M_VER}
#FROM_SERVER=http://mirrors.accretive-networks.net/mariadb/mariadb-${M_VER}/

VFILE=./galera_versions.txt
T=${VER}/${VFILE}.temp
GOOD=1

add()
{
	#$1 is the entry index
	#$2 is the version
	#$3 is the filename

	FILE=$VER/$3

	if [ ! -s $FILE ]; then
		echo "missing: $FILE";
		GOOD=0
		return;
	fi

	MD5=`md5sum $FILE | cut -d\  -f1`

	echo "$1:$2:$MD5:$3" >> $T;
}


grab()
{
	RPM_OS=$1
	ARCH=$2
	PATH_ARCH=$3
	RPM_OS_FILE=$4
	RPM_ARCH=$5

	#http://mariadb.mirror.iweb.com/mariadb-10.1.9/yum/centos7-amd64/rpms/galera-25.3.9-1.rhel7.el7.centos.x86_64.rpm

#	RPM=galera-${VER}-${REL}.${RPM_OS_FILE}.${RPM_ARCH}.rpm	
	RPM=galera-4-${VER}-${REL}.${RPM_OS_FILE}.${RPM_ARCH}.rpm	
        wget -O $VER/${RPM} ${FROM_SERVER}/yum/${RPM_OS}-${PATH_ARCH}/rpms/${RPM}
	add ${RPM_OS}_${ARCH} ${VER}-${REL} ${RPM}

	#RPM=jemalloc-devel-${VER}-${REL}.${RPM_OS_FILE}.${RPM_ARCH}.rpm
	#wget -O $VER/${RPM} ${FROM_SERVER}/yum/${RPM_OS}-${PATH_ARCH}/rpms/${RPM}
	#add ${RPM_OS}_${ARCH}_dev ${VER}-${REL} ${RPM}
}

doMain()
{
	#grab centos5 32 x86 rhel5.el5 i386
	#grab centos5 64 amd64 rhel5.el5 x86_64
	#grab centos6 32 x86 rhel6.el6 i686
	#grab centos6 64 amd64 rhel6.el6 x86_64
	grab centos7 64 amd64 el7.centos x86_64

	#galera-25.3.27-1.rhel8.0.el8.x86_64.rpm
	#grab centos8 64 amd64 rhel8.0.el8 x86_64	
	#galera-4-26.4.5-1.el8.x86_64.rpm
	grab centos8 64 amd64 el8 x86_64	
}

grab_bintar()
{
	ARCH=$1
	TGZ=galera-${VER}-${ARCH}.tar.gz
	#http://mariadb.mirror.iweb.com/mariadb-10.1.17/galera-25.3.17/bintar/galera-25.3.17-glibc_214-i686.tar.gz
	wget -O $VER/${TGZ} ${FROM_SERVER}/galera-${VER}/bintar/${TGZ}
	add bintar_${ARCH} ${VER} ${TGZ}
}

doBinTars()
{
	grab_bintar glibc_214-x86_64
	grab_bintar glibc_214-i686
	grab_bintar x86_64
}

doSource()
{
	#http://mariadb.mirror.iweb.com/mariadb-10.1.17/galera-25.3.17/src/galera-25.3.17.tar.gz
	TGZ=galera-${VER}.tar.gz
	wget -O $VER/${TGZ} ${FROM_SERVER}/galera-${VER}/src/${TGZ}
	add source ${VER} ${TGZ}
}

CWD=`pwd`
mkdir -p $VER


echo -n '' > $T

doMain
doBinTars
doSource

if [ "${GOOD}" -eq 1 ]; then
        mv -f ${T} ${VFILE}
else
        echo "Failed creation of ${T}";
        echo "check $0";
fi

exit 0;

