You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

centosinit.sh 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. # Define the CentOS Vault base URL
  3. VAULT_BASEURL="http://vault.centos.org/"
  4. # Prompt for the file pattern with a default value
  5. read -p "Enter the file pattern for repo files (default: /etc/yum.repos.d/*.repo): " repo_pattern
  6. repo_pattern="${repo_pattern:-/etc/yum.repos.d/*.repo}"
  7. # Iterate over all repo files based on the user input or the default
  8. for repo_file in $repo_pattern; do
  9. if [ -f "$repo_file" ]; then
  10. echo "Processing $repo_file..."
  11. # Comment out any mirrorlist line
  12. sudo sed -i 's/^mirrorlist=/#mirrorlist=/' "$repo_file"
  13. # Replace baseurl starting with http://mirror.centos.org/ and retain everything after it
  14. sudo sed -i 's|^#baseurl=http://mirror.centos.org/\(.*\)|baseurl=http://vault.centos.org/\1|' "$repo_file"
  15. else
  16. echo "No repo files found matching the pattern $repo_pattern"
  17. fi
  18. done
  19. echo "Completed updating all .repo files."
  20. # Function to check network connectivity
  21. check_network() {
  22. echo "Checking network connectivity..."
  23. if ping -c 4 8.8.8.8 &>/dev/null; then
  24. echo "Network is up!"
  25. else
  26. echo "Network is down. Please check your connection."
  27. exit 1
  28. fi
  29. }
  30. # Function to clean and update DNF cache
  31. clean_and_update_cache() {
  32. echo "Cleaning DNF cache..."
  33. sudo dnf clean all
  34. sudo rm -rf /var/cache/dnf
  35. echo "Rebuilding DNF cache..."
  36. sudo dnf makecache
  37. }
  38. # Function to check if AppStream repo is enabled
  39. check_appstream_repo() {
  40. echo "Checking if AppStream repository is enabled..."
  41. if sudo dnf repolist all | grep -i 'appstream' | grep -i 'enabled' &>/dev/null; then
  42. echo "AppStream repository is enabled."
  43. else
  44. echo "AppStream repository is not enabled. Enabling it now..."
  45. sudo dnf config-manager --set-enabled appstream
  46. fi
  47. }
  48. # Function to sync AppStream repository
  49. sync_appstream_repo() {
  50. echo "Syncing AppStream repository..."
  51. sudo dnf --disablerepo="*" --enablerepo="appstream" update -y
  52. }
  53. # Function to perform a system update
  54. perform_system_update() {
  55. echo "Performing system update..."
  56. sudo dnf update -y
  57. }
  58. # Main script execution
  59. echo "Starting AppStream sync process..."
  60. # Step 1: Check network connectivity
  61. check_network
  62. # Step 2: Clean and update DNF cache
  63. clean_and_update_cache
  64. # Step 3: Check if AppStream repo is enabled
  65. check_appstream_repo
  66. # Step 4: Sync AppStream repository
  67. sync_appstream_repo
  68. # Step 5: Perform a system-wide update
  69. perform_system_update
  70. echo "AppStream sync process completed!"