#!/bin/bash

# Backup existing .repo files
echo "Backing up existing repository files..."
for repo in /etc/yum.repos.d/*.repo; do
    mv "$repo" "${repo}.bak"
done

# Define the repo file path
REPO_FILE="/etc/yum.repos.d/derak-mirror.repo"

# Create the repo file
cat <<EOL > $REPO_FILE
[derak-base]
name=Derak Cloud CentOS 7 - Base
baseurl=https://archive.mirror.derak.cloud/centos/7/os/x86_64/
gpgcheck=1
gpgkey=https://archive.mirror.derak.cloud/centos/7/RPM-GPG-KEY-CentOS-7
enabled=1

[derak-updates]
name=Derak Cloud CentOS 7 - Updates
baseurl=https://archive.mirror.derak.cloud/centos/7/updates/x86_64/
gpgcheck=1
gpgkey=https://archive.mirror.derak.cloud/centos/7/RPM-GPG-KEY-CentOS-7
enabled=1

[derak-extras]
name=Derak Cloud CentOS 7 - Extras
baseurl=https://archive.mirror.derak.cloud/centos/7/extras/x86_64/
gpgcheck=1
gpgkey=https://archive.mirror.derak.cloud/centos/7/RPM-GPG-KEY-CentOS-7
enabled=1

[centos-sclo-rh]
name=CentOS-7 - SCLo rh
baseurl=https://archive.mirror.derak.cloud/centos/7/sclo/x86_64/rh/
gpgcheck=1
gpgkey=https://www.centos.org/keys/RPM-GPG-KEY-CentOS-SIG-SCLo
enabled=1

[centos-sclo-sclo]
name=CentOS-7 - SCLo sclo
baseurl=https://archive.mirror.derak.cloud/centos/7/sclo/x86_64/sclo/
gpgcheck=1
gpgkey=https://www.centos.org/keys/RPM-GPG-KEY-CentOS-SIG-SCLo
enabled=1

[CentOS-fasttrack]
name=CentOS-7 - Fasttrack
baseurl=https://archive.mirror.derak.cloud/centos/7/fasttrack/x86_64/
gpgcheck=1
gpgkey=https://archive.mirror.derak.cloud/centos/7/RPM-GPG-KEY-CentOS-7
enabled=1

[CentOS-CR]
name=CentOS-7 - Continuous Release
baseurl=https://archive.mirror.derak.cloud/centos/7/cr/x86_64/
gpgcheck=1
gpgkey=https://archive.mirror.derak.cloud/centos/7/RPM-GPG-KEY-CentOS-7
enabled=1

[CentOS-Sources]
name=CentOS-7 - Sources
baseurl=https://archive.mirror.derak.cloud/centos/7/os/Source/
gpgcheck=1
gpgkey=https://archive.mirror.derak.cloud/centos/7/RPM-GPG-KEY-CentOS-7
enabled=1

[CentOS-Plus]
name=CentOS-7 - Plus
baseurl=https://archive.mirror.derak.cloud/centos/7/centosplus/x86_64/
gpgcheck=1
gpgkey=https://archive.mirror.derak.cloud/centos/7/RPM-GPG-KEY-CentOS-7
enabled=1

[derak-infra]
name=Derak Cloud CentOS 7 - Infra
baseurl=https://archive.mirror.derak.cloud/centos/7/infra/x86_64/infra-common/
gpgcheck=0
gpgkey=https://www.centos.org/keys/RPM-GPG-KEY-CentOS-SIG-SCLo7
enabled=1
EOL

# Clean and update yum cache
yum clean all
yum repolist

echo "Derak Cloud CentOS 7 and additional CentOS repositories configured successfully."
