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