Last active
October 26, 2024 11:32
-
-
Save lesstif/d72b0d46e58bc7dfcfbed0c910833bc2 to your computer and use it in GitHub Desktop.
록키 리눅스(Rocky Linux) 미러(mirror)를 국내 포탈(navercloud)로 변경
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@m-fire 안녕하세요. 의견 주셔서 감사 드립니다.
제가 Rocky Linux 를 안 쓰는 관계로 위에서 알려주신 코드가 9 에서도 동작하는지 확인해 주시면 반영해 놓겠습니다.