Skip to content

Instantly share code, notes, and snippets.

@fumiyas
Created March 18, 2022 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fumiyas/08cf22ddd84f94ca0b6c32b922888958 to your computer and use it in GitHub Desktop.
Save fumiyas/08cf22ddd84f94ca0b6c32b922888958 to your computer and use it in GitHub Desktop.
CentOS: Replace obsolete CentOS repos with CentOS Vault mirrored in Japan
##
## CentOS: Replace obsolete CentOS repos with CentOS Vault mirrored in Japan
## Copyright (c) 2022 SATOH Fumiyasu @ OSSTech Corp., Japan
##
## License: GNU General Public License version 3
##
set -u
set -e
umask 0022
latest_baseurl="\
http://ftp.iij.ad.jp/pub/linux/centos-vault/\$contentdir/\$releasever/\\2/\$basearch/\\3/,\
http://ftp.jaist.ac.jp/pub/Linux/CentOS-vault/\$contentdir/\$releasever/\\2/\$basearch/\\3/\
"
mkdir -p /etc/yum.repos.d/dist
for repo in /etc/yum.repos.d/CentOS-*.repo; do
repo_dist="/etc/yum.repos.d/dist/$(basename $repo)"
if [[ ! -f $repo ]]; then
continue
fi
if [[ ! -f $repo_dist ]]; then
cp -a "$repo" "$repo_dist"
fi
sed \
-e 's/^\[\(.*\)\]/[\L\1]/' \
-e 's!^mirrorlist=!#&!' \
-e "s!^#* *\(baseurl=\).*/\([a-zA-Z]*\)/[^/]*/\([a-z]*\)/\$!\1$latest_baseurl!" \
<"$repo_dist" \
>"$repo" \
;
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment