|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 4 | +# SPDX-License-Identifier: Apache-2.0 |
| 5 | +# |
| 6 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | +# you may not use this file except in compliance with the License. |
| 8 | +# You may obtain a copy of the License at |
| 9 | +# |
| 10 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | +# |
| 12 | +# Unless required by applicable law or agreed to in writing, software |
| 13 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | +# See the License for the specific language governing permissions and |
| 16 | +# limitations under the License. |
| 17 | + |
| 18 | +set -euo pipefail |
| 19 | + |
| 20 | +REPO_DIR="/etc/yum.repos.d" |
| 21 | + |
| 22 | +# Disable all existing Rocky repos to prevent mirror issues |
| 23 | +for repo_file in ${REPO_DIR}/Rocky-*.repo; do |
| 24 | + if [ -f "$repo_file" ]; then |
| 25 | + sed -i 's/^enabled=1/enabled=0/g' "$repo_file" |
| 26 | + fi |
| 27 | +done |
| 28 | + |
| 29 | +# Overwrite the main Rocky repos with stable URLs |
| 30 | +# Using ONLY direct dl.rockylinux.org URLs (no mirrorlist) to avoid mirror sync issues |
| 31 | +# This prevents DNF from trying unreliable/out-of-sync mirrors |
| 32 | +cat <<'EOF' > ${REPO_DIR}/Rocky-BaseOS.repo |
| 33 | +[baseos] |
| 34 | +name=Rocky Linux 8.10 - BaseOS |
| 35 | +baseurl=https://dl.rockylinux.org/pub/rocky/8.10/BaseOS/$basearch/os/ |
| 36 | +enabled=1 |
| 37 | +gpgcheck=1 |
| 38 | +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial |
| 39 | +retries=10 |
| 40 | +timeout=30 |
| 41 | +skip_if_unavailable=False |
| 42 | +metadata_expire=1h |
| 43 | +EOF |
| 44 | + |
| 45 | +cat <<'EOF' > ${REPO_DIR}/Rocky-AppStream.repo |
| 46 | +[appstream] |
| 47 | +name=Rocky Linux 8.10 - AppStream |
| 48 | +baseurl=https://dl.rockylinux.org/pub/rocky/8.10/AppStream/$basearch/os/ |
| 49 | +enabled=1 |
| 50 | +gpgcheck=1 |
| 51 | +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial |
| 52 | +retries=10 |
| 53 | +timeout=30 |
| 54 | +skip_if_unavailable=False |
| 55 | +metadata_expire=1h |
| 56 | +EOF |
| 57 | + |
| 58 | +cat <<'EOF' > ${REPO_DIR}/Rocky-Extras.repo |
| 59 | +[extras] |
| 60 | +name=Rocky Linux 8.10 - Extras |
| 61 | +baseurl=https://dl.rockylinux.org/pub/rocky/8.10/extras/$basearch/os/ |
| 62 | +enabled=1 |
| 63 | +gpgcheck=1 |
| 64 | +gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial |
| 65 | +retries=10 |
| 66 | +timeout=30 |
| 67 | +skip_if_unavailable=False |
| 68 | +metadata_expire=1h |
| 69 | +EOF |
| 70 | + |
| 71 | +# Clean DNF cache and refresh repository metadata with retry logic |
| 72 | +dnf clean all |
| 73 | + |
| 74 | +max_attempts=3 |
| 75 | +attempt=1 |
| 76 | +while [ $attempt -le $max_attempts ]; do |
| 77 | + if dnf makecache --refresh; then |
| 78 | + break |
| 79 | + else |
| 80 | + if [ $attempt -lt $max_attempts ]; then |
| 81 | + sleep $((2 ** attempt)) |
| 82 | + else |
| 83 | + echo "ERROR: Failed to refresh repository metadata after $max_attempts attempts" |
| 84 | + exit 1 |
| 85 | + fi |
| 86 | + fi |
| 87 | + attempt=$((attempt + 1)) |
| 88 | +done |
0 commit comments