Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add mirror variables #116

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion migrate2rocky/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Running this script will convert an existing CentOS 8 system to Rocky Linux 8.
#### Use Mirror URLs of Rocky Linux

```bash
export ROCKY_LINUX_ENV_MIRROR_URL="https://mirrors.example.org/rocky"
export ROCKY_ENV_MIRROR_URL="https://mirrors.example.org/rocky"

./migrate2rocky.sh -r
```
Expand Down
20 changes: 11 additions & 9 deletions migrate2rocky/migrate2rocky.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,10 @@ SUPPORTED_PLATFORM="platform:el$SUPPORTED_MAJOR"
ARCH=$(arch)

# Use Mirror URLs of Rocky Linux from environment if set.
ROCKY_LINUX_DEFAULT_URL="https://dl.rockylinux.org/pub/rocky"
ROCKY_LINUX_MIRROR_URL="${ROCKY_LINUX_ENV_MIRROR_URL:-"${ROCKY_LINUX_DEFAULT_URL}"}"
ROCKY_DEFAULT_URL="https://dl.rockylinux.org/pub/rocky"
ROCKY_MIRROR_URL="${ROCKY_ENV_MIRROR_URL:-"${ROCKY_DEFAULT_URL}"}"

gpg_key_url="${ROCKY_LINUX_MIRROR_URL}/RPM-GPG-KEY-rockyofficial"
gpg_key_url="${ROCKY_MIRROR_URL}/RPM-GPG-KEY-rockyofficial"
gpg_key_sha512="88fe66cf0a68648c2371120d56eb509835266d9efdf7c8b9ac8fc101bdf1f0e0197030d3ea65f4b5be89dc9d1ef08581adb068815c88d7b1dc40aa1c32990f6a"

sm_ca_dir=/etc/rhsm/ca
Expand All @@ -127,8 +127,8 @@ unset tmp_sm_ca_dir
# all repos must be signed with the same key given in $gpg_key_url
declare -A repo_urls
repo_urls=(
[rockybaseos]="${ROCKY_LINUX_MIRROR_URL}/${SUPPORTED_MAJOR}/BaseOS/$ARCH/os/"
[rockyappstream]="${ROCKY_LINUX_MIRROR_URL}/${SUPPORTED_MAJOR}/AppStream/$ARCH/os/"
[rockybaseos]="${ROCKY_MIRROR_URL}/${SUPPORTED_MAJOR}/BaseOS/$ARCH/os/"
[rockyappstream]="${ROCKY_MIRROR_URL}/${SUPPORTED_MAJOR}/AppStream/$ARCH/os/"
)

# The repos package for CentOS stream requires special handling.
Expand Down Expand Up @@ -850,11 +850,13 @@ EOF
fi

# Replace mirror
if [ -n "$ROCKY_LINUX_ENV_MIRROR_URL" ]; then
if [[ $ROCKY_ENV_MIRROR_URL ]]; then
local -a repo_files
readarray -t repo_files < <(rpm -ql rocky-repos | grep '\.repo$')
sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl='${ROCKY_LINUX_MIRROR_URL}'|g' \
-i.bak \
/etc/yum.repos.d/Rocky-*.repo
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl='"$ROCKY_MIRROR_URL"'|g' \
-i.migrate2rocky \
"${repo_files[@]}"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By doing this, you uncomment baseurl in files where whole sections are commented, breaking the ini file (i.e. Rocky-Sources.repo

*** /etc/yum.repos.d/Rocky-Sources.repo 2021-12-22 03:25:09.000000000 +0100
--- /proc/self/fd/14    2022-02-16 14:35:54.429740900 +0100
***************
*** 1,58 ****
  # Rocky-Sources.repo

  [baseos-source]
  name=Rocky Linux $releasever - BaseOS - Source
! mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=source&repo=BaseOS-$releasever-source
! #baseurl=http://dl.rockylinux.org/$contentdir/$releasever/BaseOS/source/tree/
  gpgcheck=1
  enabled=0
  gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial

  [appstream-source]
  name=Rocky Linux $releasever - AppStream - Source
! mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=source&repo=AppStream-$releasever-source
! #baseurl=http://dl.rockylinux.org/$contentdir/$releasever/AppStream/source/tree/
  gpgcheck=1
  enabled=0
  gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial

  #[extras-source]
  #name=Rocky Linux $releasever - Extras - Source
  #mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=source&repo=extras-$releasever-source
! #baseurl=http://dl.rockylinux.org/$contentdir/$releasever/extras/source/tree/
  #gpgcheck=1
  #enabled=0
  #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial

  #[plus-source]
  #name=Rocky Linux $releasever - Plus - Source
  #mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=source&repo=plus-$releasever-source
! #baseurl=http://dl.rockylinux.org/$contentdir/$releasever/Plus/source/tree/
  #gpgcheck=1
  #enabled=0
  #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial

  [ha-source]
  name=Rocky Linux $releasever - High Availability - Source
! mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=source&repo=HighAvailability-$releasever-source
! #baseurl=http://dl.rockylinux.org/$contentdir/$releasever/HighAvailability/source/tree/
  gpgcheck=1
  enabled=0
  gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial

  [powertools-source]
  name=Rocky Linux $releasever - PowerTools - Source
! mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=source&repo=PowerTools-$releasever-source
! #baseurl=http://dl.rockylinux.org/$contentdir/$releasever/PowerTools/source/tree/
  gpgcheck=1
  enabled=0
  gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial

  [resilient-storage-source]
  name=Rocky Linux $releasever - Resilient Storage - Source
! mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=source&repo=ResilientStorage-$releasever-source
! #baseurl=http://dl.rockylinux.org/$contentdir/$releasever/ResilientStorage/source/tree/
  gpgcheck=1
  enabled=0
  gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial

--- 1,58 ----
  # Rocky-Sources.repo

  [baseos-source]
  name=Rocky Linux $releasever - BaseOS - Source
! #mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=source&repo=BaseOS-$releasever-source
! baseurl=/$releasever/BaseOS/source/tree/
  gpgcheck=1
  enabled=0
  gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial

  [appstream-source]
  name=Rocky Linux $releasever - AppStream - Source
! #mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=source&repo=AppStream-$releasever-source
! baseurl=/$releasever/AppStream/source/tree/
  gpgcheck=1
  enabled=0
  gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial

  #[extras-source]
  #name=Rocky Linux $releasever - Extras - Source
  #mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=source&repo=extras-$releasever-source
! baseurl=/$releasever/extras/source/tree/
  #gpgcheck=1
  #enabled=0
  #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial

  #[plus-source]
  #name=Rocky Linux $releasever - Plus - Source
  #mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=source&repo=plus-$releasever-source
! baseurl=/$releasever/Plus/source/tree/
  #gpgcheck=1
  #enabled=0
  #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial

  [ha-source]
  name=Rocky Linux $releasever - High Availability - Source
! #mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=source&repo=HighAvailability-$releasever-source
! baseurl=/$releasever/HighAvailability/source/tree/
  gpgcheck=1
  enabled=0
  gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial

  [powertools-source]
  name=Rocky Linux $releasever - PowerTools - Source
! #mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=source&repo=PowerTools-$releasever-source
! baseurl=/$releasever/PowerTools/source/tree/
  gpgcheck=1
  enabled=0
  gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial

  [resilient-storage-source]
  name=Rocky Linux $releasever - Resilient Storage - Source
! #mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=source&repo=ResilientStorage-$releasever-source
! baseurl=/$releasever/ResilientStorage/source/tree/
  gpgcheck=1
  enabled=0
  gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial

fi

# Distrosync
Expand Down