#!/bin/bash # 0.1 Update Resolv.conf (DNS Setup) echo "Setting up DNS servers in /etc/resolv.conf..." cat << EOF > /etc/resolv.conf nameserver 2.189.44.44 nameserver 87.107.110.110 EOF # 0.2 Update AlmaLinux GPG Key (Fix for 2024 Key Expiration) echo "Checking and updating AlmaLinux GPG keys..." if [ -f /etc/redhat-release ] && grep -q "AlmaLinux" /etc/redhat-release; then # Import the new GPG key directly from official source rpm --import https://almalinux.mobinhost.com/RPM-GPG-KEY-AlmaLinux echo "GPG keys imported successfully." else echo "Not an AlmaLinux system or release file missing, skipping GPG import." fi # 1. Setup Backup Directory BACKUP_DIR="/root/repo" REPO_DIR="/etc/yum.repos.d" echo "Setting up backup in $BACKUP_DIR..." mkdir -p "$BACKUP_DIR" cp "$REPO_DIR"/*.repo "$BACKUP_DIR/" 2>/dev/null # 2. Process AlmaLinux Repos echo "Processing AlmaLinux repository files..." for repo_file in "$REPO_DIR"/[Aa][Ll][Mm][Aa]*.repo; do if [ -f "$repo_file" ]; then if grep -q "almalinux.mobinhost.com" "$repo_file"; then echo "Skipping $repo_file: Already configured for Mobinhost." else echo "Updating $repo_file..." sed -i 's/^\s*mirrorlist=/#mirrorlist=/g' "$repo_file" sed -i 's/^#\s*baseurl=/baseurl=/g' "$repo_file" sed -i 's|https://repo.almalinux.org/almalinux/|https://almalinux.mobinhost.com/|g' "$repo_file" fi fi done # 3. Install EPEL Release if ! rpm -q epel-release > /dev/null 2>&1; then echo "Installing epel-release..." dnf install -y epel-release else echo "epel-release is already installed." fi # 4. Process epel.repo EPEL_FILE="$REPO_DIR/epel.repo" if [ -f "$EPEL_FILE" ]; then if grep -q "epel.mobinhost.com" "$EPEL_FILE"; then echo "Skipping $EPEL_FILE: Already configured for Mobinhost." else echo "Updating $EPEL_FILE..." sed -i 's/^\s*metalink=/#metalink=/g' "$EPEL_FILE" sed -i 's/^#\s*baseurl=/baseurl=/g' "$EPEL_FILE" sed -i 's|https://download.example/pub/epel/|https://epel.mobinhost.com/|g' "$EPEL_FILE" sed -i 's|https://download.fedoraproject.org/pub/epel/|https://epel.mobinhost.com/|g' "$EPEL_FILE" fi fi # 5. Disable epel-cisco-openh264 CISCO_REPO="$REPO_DIR/epel-cisco-openh264.repo" if [ -f "$CISCO_REPO" ]; then if grep -q "enabled=1" "$CISCO_REPO"; then echo "Disabling epel-cisco-openh264..." sed -i 's/enabled=1/enabled=0/g' "$CISCO_REPO" else echo "epel-cisco-openh264 is already disabled." fi fi # 6. Final Refresh echo "Cleaning and refreshing DNF cache..." dnf clean all dnf makecache echo "------------------------------------------------" echo "Configuration updated successfully." echo "Backup stored at: $BACKUP_DIR"