12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #!/bin/bash
-
- # Define the CentOS Vault base URL
- VAULT_BASEURL="http://vault.centos.org/"
-
- # Prompt for the file pattern with a default value
- read -p "Enter the file pattern for repo files (default: /etc/yum.repos.d/*.repo): " repo_pattern
- repo_pattern="${repo_pattern:-/etc/yum.repos.d/*.repo}"
-
- # Iterate over all repo files based on the user input or the default
- for repo_file in $repo_pattern; do
- if [ -f "$repo_file" ]; then
- echo "Processing $repo_file..."
-
- # Comment out any mirrorlist line
- sudo sed -i 's/^mirrorlist=/#mirrorlist=/' "$repo_file"
-
- # Replace baseurl starting with http://mirror.centos.org/ and retain everything after it
- sudo sed -i 's|^#baseurl=http://mirror.centos.org/\(.*\)|baseurl=http://vault.centos.org/\1|' "$repo_file"
- else
- echo "No repo files found matching the pattern $repo_pattern"
- fi
- done
-
- echo "Completed updating all .repo files."
-
- # Function to check network connectivity
- check_network() {
- echo "Checking network connectivity..."
- if ping -c 4 8.8.8.8 &>/dev/null; then
- echo "Network is up!"
- else
- echo "Network is down. Please check your connection."
- exit 1
- fi
- }
-
- # Function to clean and update DNF cache
- clean_and_update_cache() {
- echo "Cleaning DNF cache..."
- sudo dnf clean all
- sudo rm -rf /var/cache/dnf
- echo "Rebuilding DNF cache..."
- sudo dnf makecache
- }
-
- # Function to check if AppStream repo is enabled
- check_appstream_repo() {
- echo "Checking if AppStream repository is enabled..."
- if sudo dnf repolist all | grep -i 'appstream' | grep -i 'enabled' &>/dev/null; then
- echo "AppStream repository is enabled."
- else
- echo "AppStream repository is not enabled. Enabling it now..."
- sudo dnf config-manager --set-enabled appstream
- fi
- }
-
- # Function to sync AppStream repository
- sync_appstream_repo() {
- echo "Syncing AppStream repository..."
- sudo dnf --disablerepo="*" --enablerepo="appstream" update -y
- }
-
- # Function to perform a system update
- perform_system_update() {
- echo "Performing system update..."
- sudo dnf update -y
- }
-
- # Main script execution
- echo "Starting AppStream sync process..."
-
- # Step 1: Check network connectivity
- check_network
-
- # Step 2: Clean and update DNF cache
- clean_and_update_cache
-
- # Step 3: Check if AppStream repo is enabled
- check_appstream_repo
-
- # Step 4: Sync AppStream repository
- sync_appstream_repo
-
- # Step 5: Perform a system-wide update
- perform_system_update
-
- echo "AppStream sync process completed!"
|