Skip to content

Instantly share code, notes, and snippets.

@lesstif
Last active June 6, 2023 14:37
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lesstif/d72b0d46e58bc7dfcfbed0c910833bc2 to your computer and use it in GitHub Desktop.
Save lesstif/d72b0d46e58bc7dfcfbed0c910833bc2 to your computer and use it in GitHub Desktop.
록키 리눅스(Rocky Linux) 미러(mirror)를 국내 포탈(navercloud)로 변경
#!/usr/bin/env bash
##
REPOS_FILES="AppStream BaseOS"
PARAM="hn"
#KAKAO="mirror.kakao.com\/centos"
NAVER="mirror.navercorp.com\/rocky"
if [ "$(id -u)" != "0" ]; then
echo "'$0' must be run as root" 1>&2
exit 1
fi
function usage {
echo "USAGE: $0 [OPTION] ";
echo -e "\r\n-b : make backup file";
# echo "-r[repostiroy.file] : specify yum repository file (default ${BASE_REPOS})"
# echo "-k : use kakao mirror (${KAKAO})"
echo "-n : use naver mirror (${NAVER})"
exit 0;
}
REMOTE_REPOS=${NAVER}
releasever=$(cat /etc/redhat-release | tr -dc '0-9.'|cut -d \. -f1)
basearch=x86_64
while getopts $PARAM opt; do
case $opt in
r)
echo "-r option was supplied. OPTARG: $OPTARG" >&2
REMOTE_REPOS=$OPTARG;
;;
k)
echo "Using Kakao repository(${REPOS})." >&2
REMOTE_REPOS=${KAKAO}
;;
n)
echo "Using naver repository(${NAVER})." >&2
REMOTE_REPOS=${NAVER}
;;
h)
usage;
;;
esac
done
for i in ${REPOS_FILES};do
R="/etc/yum.repos.d/Rocky-${i}.repo";
FULL_REPOS_PATH="http:\/\/${REMOTE_REPOS}\/${releasever}\/${i}\/${basearch}\/os"
if [ ! -f ${R} ];then
continue;
fi
echo "using repository(${R})";
## change mirror
sed -i.bak -re "s/^(mirrorlist(.*))/##\1/g" -re "s/[#]*baseurl(.*)/baseurl=${FULL_REPOS_PATH}/" ${R}
done
## check
yum check-update
yum repolist baseos -v
yum repolist appstream -v
@lesstif
Copy link
Author

lesstif commented Nov 2, 2021

@palindrom615 주신 의견 반영해서 수정했습니다.

@m-fire
Copy link

m-fire commented May 31, 2023

좋은코드 감사해요. 이 스크립트는 8 전용인 듯 합니다. 한가지 건의사항 남깁니다.

line 28

releasever=$(cat /etc/redhat-release | tr -dc '0-9.' | cut -d \. -f1)

여기서 | cut -d \. -f1 코드를 제거 하면, 하위( 8.x )버전도 커버하지 않을까요?

추가정보:
이 스크립트는 9.x 버전을 지원하지 않습니다.
Rocky 9.x 로 넘어오면서 /etc/yum.repo.d 내부에 파일명이 다르고, 갯수도 줄었습니다.

@lesstif
Copy link
Author

lesstif commented Jun 6, 2023

@m-fire 안녕하세요. 의견 주셔서 감사 드립니다.

제가 Rocky Linux 를 안 쓰는 관계로 위에서 알려주신 코드가 9 에서도 동작하는지 확인해 주시면 반영해 놓겠습니다.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment