#!/bin/bash
# Ensure the script is run as root
if [ "$EUID" -ne 0 ]; then
echo "Please run as root (use sudo)"
exit 1
fi
echo "--- Starting CentOS 7 Repo Fix ---"
# 1. Create backup directory
BACKUP_DIR="/etc/yum.repos.d/backup_$(date +%Y%m%d_%H%M%S)"
echo "Step 1: Backing up current repos to $BACKUP_DIR"
mkdir -p "$BACKUP_DIR"
cp /etc/yum.repos.d/*.repo "$BACKUP_DIR/"
# 2. Clear out old repo files
echo "Step 2: Removing old repository configurations..."
rm -f /etc/yum.repos.d/CentOS-*.repo
# 3. Create the new Base repo file
echo "Step 3: Creating new Vault-based configuration..."
cat <<EOF > /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-\$releasever - Base
baseurl=https://vault.centos.org/7.9.2009/os/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1
[updates]
name=CentOS-\$releasever - Updates
baseurl=https://vault.centos.org/7.9.2009/updates/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1
[extras]
name=CentOS-\$releasever - Extras
baseurl=https://vault.centos.org/7.9.2009/extras/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=1
[centosplus]
name=CentOS-\$releasever - CentOSPlus
baseurl=https://vault.centos.org/7.9.2009/centosplus/\$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
enabled=0
EOF
# 4. Refresh YUM cache
echo "Step 4: Cleaning and rebuilding YUM cache..."
yum clean all
yum makecache
echo "--- Success! CentOS 7 is now pointing to the Vault ---"