#!/bin/bash

mirror="mirror2.gohost.kz"
drbdVer="9.2.14"
drbdType="prod"
oneVer="7.0"
ALV="9"


sed -i "s/repo.almalinux.org/$mirror/g" /etc/yum.repos.d/almalinux*
sed -i "s/^#.*baseurl=http/baseurl=http/g" /etc/yum.repos.d/almalinux*
sed -i "s/^mirrorlist=http/#mirrorlist=http/g" /etc/yum.repos.d/almalinux*

if [ -f /etc/yum.repos.d/epel.repo ] 
then
    sed -i "s/download.example\/pub/$mirror/g" /etc/yum.repos.d/epel*
    sed -i "s/download.fedoraproject.org\/pub/$mirror/g" /etc/yum.repos.d/epel*
    sed -i "s/^#.*baseurl=http/baseurl=http/g" /etc/yum.repos.d/epel*
    sed -i "s/^metalink=http/#metalink=http/g" /etc/yum.repos.d/epel*
else 
    cat <<EOF> /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux $ALV - \$basearch
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place its address here.
baseurl=https://$mirror/epel/$ALV/Everything/\$basearch
#metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-$ALV&arch=\$basearch&infra=\$infra&content=\$contentdir
enabled=1
gpgcheck=0
countme=1
EOF
fi

if [ -f /etc/yum.repos.d/zfs.repo ]
then
    sed -i "s/download.zfsonlinux.org/$mirror\/zfs/g" /etc/yum.repos.d/zfs.repo
else
    cat <<EOF> /etc/yum.repos.d/zfs.repo
[zfs]
name=ZFS on Linux for EL8 - dkms
baseurl=http://$mirror/zfs/epel/$ALV/\$basearch/
enabled=1
metadata_expire=7d
gpgcheck=0
EOF
fi

cat <<EOF> /etc/yum.repos.d/linstor.repo
[linstor]
name=linstor
baseurl=https://$mirror/drbd-lin/$drbdVer/almalinux/\$releasever/$drbdType/
enabled=1
gpgcheck=0
EOF

if [ -f /etc/yum.repos.d/opennebula.repo ]
then
    sed -i "s/downloads.opennebula.io/$mirror\/opennebula/g" /etc/yum.repos.d/zfs.repo
else
    cat <<EOF> /etc/yum.repos.d/opennebula.repo 
[opennebula]
name=OpenNebula Enterprise Edition
baseurl=https://$mirror/opennebula/repo/$oneVer/AlmaLinux/\$releasever/\$basearch
enabled=1
gpgkey=https://$mirror/opennebula/repo/repo2.key
gpgcheck=1
repo_gpgcheck=1
EOF
fi

if [ -f /etc/yum.repos.d/frr-stable.repo ]
then
    sed -i "s/rpm.frrouting.org\/repo\/el8/mirror2.gohost.kz\/frr/g" /etc/yum.repos.d/frr-stable.repo
else
    cat <<EOF> /etc/yum.repos.d/frr-stable.repo
[frr]
name=FRRouting Packages for Enterprise Linux 8 - \$basearch
baseurl=https://$mirror/frr/el$ALV/frr
enabled=1
gpgcheck=0

[frr-RPKI]
name=FRRouting Packages with RPKI for Enterprise Linux 8 - \$basearch
baseurl=https://$mirror/frr/el$ALV/frr-rpki
enabled=0
gpgcheck=0

[frr-extras]
name=FRRouting Dependencies for Enterprise Linux 8 - \$basearch
baseurl=https://$mirror/frr/el$ALV/extras
enabled=1
gpgcheck=0
EOF
fi
